Fork me on GitHub
#reagent
<
2017-01-07
>
dottedmag14:01:25

Is there a way to pass a ratom to the top component (via render-component)?

pesterhazy15:01:31

there is, but why?

dottedmag15:01:11

I see it can be done via (defn top-component [] [sub-component my-ratom]) and wonder whether the top-component is necessary in this case.

dottedmag15:01:29

But then I'm probably doing something utterly wrong.

metametadata15:01:35

@dottedmag something like this?

(defn top-component
   [data-ratom]
  [:p (pr-str @data-ratom)])

; render == render-component
(r/render [top-component my-data-ratom] (.getElementById js/document "root"))

dottedmag15:01:13

Ah, so render accepts not only a component, but also a vector of component and arguments. Thanks!

pesterhazy15:01:58

consider that it's pretty convenient to have direct access to the ratom, rather than threading it through every component

pesterhazy15:01:44

the only reason I can think of to make it an explicit parameter is unit testing

dottedmag15:01:10

Or creating several instances of a single app on a page. Which is admittedly rare occasion.

dottedmag15:01:01

I was just reading tutorial and found out the lack of symmetry intriguing. Now I see the symmetry is not lacking, as the way to pass arguments is the same in r/render and inside the components.