This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-28
Channels
- # aleph (4)
- # announcements (5)
- # babashka (28)
- # babashka-sci-dev (13)
- # beginners (63)
- # calva (76)
- # cider (113)
- # clara (7)
- # clj-kondo (42)
- # cljdoc (1)
- # clojure (170)
- # clojure-europe (20)
- # clojure-nl (17)
- # clojure-norway (3)
- # clojure-spec (12)
- # clojure-sweden (1)
- # clojure-uk (6)
- # clojurescript (55)
- # clojureverse-ops (1)
- # consulting (1)
- # core-async (9)
- # cursive (16)
- # data-science (1)
- # datascript (8)
- # datomic (27)
- # emacs (14)
- # events (1)
- # fulcro (10)
- # graphql (9)
- # gratitude (1)
- # jobs (6)
- # jobs-discuss (5)
- # leiningen (10)
- # lsp (35)
- # missionary (4)
- # nextjournal (9)
- # off-topic (46)
- # pathom (15)
- # pedestal (5)
- # polylith (37)
- # portal (15)
- # re-frame (22)
- # reagent (4)
- # reitit (5)
- # reveal (18)
- # shadow-cljs (20)
- # tools-deps (7)
- # xtdb (10)
Hello all. Reagent's `reagent.core/children` does not work with functional component. 😞 fortunately, as `reagent.core/current-component` returns mocking object, I write a helper function like below:
(defn get-children [^js this]
(if (.-props this)
(reagent.core/children this)
(when-some [v (.-argv this)]
(reagent.impl.component/extract-children v))))
Can I safely use it for functional component? for example
(defmacro nest-children []
`(some->> (reagent.core/current-component)
(get-children)
(into [:<>])))
(defn fn-comp [{:keys [prop1]}]
[:div
(str "Prop1 is " prop1)
(nest-children)])
(defn demo []
[:f> fn-comp
{:prop1 "hello"}
[:span "world"]
[:span "foo"]
[:span "bar"]])
It seems work for simple tests.
The reason I wrote nest-children
is that basic solution like below is verbose and seems ugly to me. (especially, parameter declaration part is not good in terms of readability.)
(defn fn-comp [{:keys [prop1
prop2
on-change-prop1]} & children]
[:div
(when (seq children)
(into [:<>] children]))])
Or any better solution to write nest-children
without macro?
Thanks.