This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-04
Channels
- # announcements (1)
- # architecture (16)
- # asami (30)
- # babashka (1)
- # beginners (17)
- # calva (4)
- # clj-kondo (4)
- # clojure (32)
- # clojure-austin (2)
- # clojure-dev (16)
- # clojure-europe (33)
- # clojure-mexico (1)
- # clojurescript (40)
- # data-science (9)
- # emacs (33)
- # fulcro (1)
- # jackdaw (4)
- # malli (25)
- # off-topic (34)
- # pathom (23)
- # react (16)
- # reagent (8)
- # releases (5)
- # vim (46)
How would you define a reagent component so it can be used as the basic hiccup dom components. Example for the component comp
:
[comp "Hello"]
[comp {:my-prop val} "hello"]
[comp]
[comp {:my-other-prop val}
[comp2]
[comp3]]
If you want a parent that can host children, then you can use [props & children]
for your argument list e.g.
(defn comp
"Reproduces your last example"
[{:keys [my-other-prop]} & children]
[:div
[:p "my other prop: " my-other-prop]
(into [:<>] children)])
disclaimer: didn’t test; react may complain about lack of keys in the child componentsIf you’re asking whether you can define a component that can optionally take in props and optionally take in children, then you’ll want to make a multi-arity function
But wouldn't this approach fail if you pass children and no props? It seems that reagent would take the first param which is children to be the props map
yes, so in the case of 1-arity you’d want to distinguish maps and other objects to decide how to treat the argument
I see. Thank you!
(defn container
[& _]
(let [this (r/current-component)
props (r/props this)
children (r/children this)]
;; render login
[:div {:class-name "container mx-auto px-4 bg-slate-100 dark:bg-slate-900"}]))
^ is this considered to be bad practice for the given context?