This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-22
Channels
- # 100-days-of-code (1)
- # beginners (51)
- # carry (1)
- # cider (10)
- # clojure (71)
- # clojure-conj (4)
- # clojure-dev (9)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-russia (8)
- # clojure-uk (16)
- # clojurescript (42)
- # cursive (4)
- # datomic (2)
- # emacs (8)
- # figwheel-main (7)
- # fulcro (20)
- # hyperfiddle (5)
- # jobs (2)
- # off-topic (16)
- # om-next (4)
- # onyx (9)
- # powderkeg (1)
- # re-frame (8)
- # reagent (17)
- # reitit (41)
- # robots (6)
- # rum (1)
- # shadow-cljs (54)
- # testing (3)
- # tools-deps (19)
@hkjels you can use fragments or you can just use reduce
instead of map
to create a single vector

What is going on here?
(defn my-comp
[{:keys [class] :as props} & children]
(into [:div {:class ["class-one" class]}] children))
; works
[my-comp {} [:div ] [:div ]]
; does not work
[my-comp [:div ] [:div ]]
By “does not work” I mean that I would expect the second to also render the :div
s but it does not…For some reason I was thinking that reagent was expecting the first to always be a map (and this would become props) and if not a map everything else would become children
I wish that were the case. The only thing it does that is special with a props map is that it will put a props map on the actual props
property and the remainder of the arguments on props.children
How would I go about defining my-comp
so I could pass it a map, or not, and behave as I expect?
you could check the type of the props object. if it is a vector then treat it as a child
haha that was what I wanted to do, but for some reason I have not seen this pattern in any example code I reviewed.
I figured this would be pretty common
The common case I can think of is when creating a component library:
(defn para
[props & children]
(into [:p props] children))
In the above example, component libraries will often make it so that the component has sane defaults which would mean that for most case you just need to call
[para "This is a paragraph"]
and then overwriting defaults is allowed by providing a map as the first arg
is the accepted way in reagent to do
(defn para
[props & children]
(if ( = props map)
;; stuff 1
;; stuff 2
Good to know. Yeah, I was working on this and was blown away that after several months of solid reagent I had not come across this. I also read through this (quickly, I admit) https://github.com/reagent-project/reagent/issues/13 and it had me thinking that reagent built in a solution