Thanks Mike, I had seen that already. IMHO it does not really explain this
properly because props are only used in the render function in that example but
not in the lifecycle hooks.
My current solution is to use `reagent.core/props` (public api, not an impl.
like get-props, just a thin wrapper for it though) in the hooks. Here is a
small working example. Pay attention to the usage of `props` in the first let
block.
Is this supposed to be the idiomatic way to do it?
(defn- plot
([comp]
(let [data [{:label "foo"
:data (-> comp reagent/props :data)}]
(.plot js/$ (reagent/dom-node comp) (clj->js data) (clj->js
plot-options)))))
(defn plot-component []
(reagent/create-class
{:component-did-mount plot
:component-did-update plot
:display-name "plot-component"
:reagent-render (fn []
[:div.plot-container {:style {:width "100%"
:height "500px"}}])}))
;; use the component like this:
; [plot/plot-component {:data (:plot-data @app-state)]]]])
As you can see, I do not have explicit props in the component function
parameters even though I pass it when using the component. Is that bad practice?
I was struggling to get this whole thing working because I had another, only
slightly related bug: I was passing props to the component not as a map (as can
be seen above), but used a vector directly (the only prop I needed). This
caused weird behaviours.
I put out a small blog post about this:
http://nils-blum-oeste.net/clojurescripts-reagent-using-props-in-lifecycle-hooks/
Going to add an example to
https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components too if this
gets confirmed to be the right way to do it.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.