reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
johnnyillinois 2020-07-16T06:32:42.041800Z

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-himik 2020-07-16T06:38:02.042200Z

Your code is just fine. A regular HOC.

johnnyillinois 2020-07-16T06:49:50.042400Z

🙌

2020-07-16T13:42:39.043Z

Thank you - that's more or less what I ended up doing, with a document-level copy/paste listener. It has its own challenges, but it seems more manageable since it's in my control.