Fork me on GitHub
#reagent
<
2020-07-16
>
johnnyillinois06:07:42

This might be a noobie question but I’m wondering what would be the “recommended way” to create a reagent component which “takes as input” 2 other components and displays one or the other depending on some internal state. For example:

(defn hello-a [] [:div "a"])
(defn hello-b [] [:div "b"])

(def possibly-true? (zero? (rand-int 2)))

(defn choose-a-or-b
  [{:keys [view-1 view-2]
  (if possibly-true?
    [view-1]
    [view-2]))

(defn home-page
  []
  [choose-a-or-b {:view-1 hello-a :view-2 hello-b}])

p-himik06:07:02

Your code is just fine. A regular HOC.