Fork me on GitHub
#reagent
<
2019-09-12
>
jplaza23:09:40

Hi people! 👋 I don’t know if this is idiomatic reagent, but I would like to create custom components that behave as :div or any other HTML element. For example: With :div I can add the number of children I like without having to specify a :key prop

[:div {:class "mydiv"} [:span "Click"] [:a "here"]]
I would like to do the same if I define, let’s say a window component
[window
 [nav "Home" "Pics" "About"]
 [title "Pictures"]
 [:section [:div "Awesome Pics"]]]
Or
[window
 [nav "Home" "Pics" "About"]
 [:div "This is home"]]

jplaza23:09:02

Would this make sense?

(defn window
  [& children]
  [:div.window
   (for [child children]
     ^{:key child} child)])

lilactown23:09:12

if it’s not a truly dynamic list, I would use into

lilactown23:09:55

e.g. (into [:div.window] children)