What should the om component return in order to do nothing?

Is it possible to write a component that does not display anything, for example, if its cursor data is empty?

I can not do

(defn count-or-nothing [list-cursor owner]
  (reify
    om/IRender
    (render [_]
       (if (not (empty? list-cursor))
         (dom/div nil "You have some elements !")))))

The if clause returns nil, which causes an error message

Missed error: Invariant violation: ReactCompositeComponent.render (): A valid ReactComponent must be returned. You may have returned null, undefined, an array, or some other invalid object.

Going through the void, but that sounds awkward. Do I have to reorganize my code and get a test "outside" of this component?

+4
source share
2 answers

, , - , React DOM , response-id . , React , DOM ( ). , .

, , PARENT . , , ... .

(defn something-interesting [list-cursor owner]
  (reify
    om/IRender
    (render [_]
      (dom/div nil "You have some elements !"))))

(defn count-or-nothing [list-cursor owner]
  (reify
    om/IRender
    (render [_]
      (dom/div nil
        ; Other UI stuff here maybe...
        (when-not (empty? list-cursor)
          (om/build something-interesting list-cursor))))))
+6

, : .

OM, ...

[EDIT] ​​

+1

Source: https://habr.com/ru/post/1546271/


All Articles