Fork me on GitHub
#reagent
<
2020-06-13
>
Brady Pierce21:06:05

How do you access a components children in reagent?

Brady Pierce21:06:35

(defn container [props]
  (let [comp (r/current-component)
        children (r/children comp)]
    [rn/view {:style (merge {:padding 24} (:style props))}
     [children]]))
I tried using r/current-component and r/children but children is coming back as null

lilactown22:06:18

children are passed as arguments

lilactown22:06:43

so assuming you're rendering like [container {} [child1] [child2]]

lilactown22:06:15

the arguments passed to container will be:

(defn container [props child1 child2]
  ,,,)

lilactown22:06:39

you can use [props & children] to refer to a variable number of children