This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-19
Channels
- # beginners (240)
- # boot (9)
- # braveandtrue (2)
- # bristol-clojurians (2)
- # cider (2)
- # cljsrn (84)
- # clojars (1)
- # clojure (195)
- # clojure-belgium (9)
- # clojure-china (5)
- # clojure-denmark (4)
- # clojure-italy (7)
- # clojure-mke (1)
- # clojure-norway (1)
- # clojure-russia (16)
- # clojure-spec (74)
- # clojure-uk (15)
- # clojurescript (78)
- # clr (3)
- # code-reviews (4)
- # datascript (8)
- # datomic (71)
- # emacs (9)
- # hoplon (18)
- # jobs (3)
- # kekkonen (32)
- # klipse (19)
- # lambdaisland (2)
- # luminus (15)
- # off-topic (6)
- # om (35)
- # om-next (62)
- # onyx (17)
- # overtone (5)
- # pedestal (1)
- # perun (1)
- # planck (31)
- # protorepl (1)
- # re-frame (135)
- # reagent (34)
- # ring-swagger (6)
- # rum (54)
- # specter (3)
- # untangled (14)
- # yada (14)
Hi, I'm a bit puzzled by this paragraph from re-frame docs, is it specific to re-frame or concern reagent as well?
Lifecycle Functions When props change, the entire underlying React machinery is engaged. React Components can have lifecycle methods like component-did-update and these functions will get called, just as they would if you were dealing with a React Component. But ... when the rerender is re-run because an input ratom changed, Lifecycle functions are not run. So, for example, component-did-update will not be called on the Component. Careful of this one. It trips people up.
I commented elsewhere already, but my answer would be: it's not specific to re-frame. The confusing wordings are, in my opinion, "input ratom" and "ratom changed". It should say "When a dereferenced reagent/atom
's contents changed, the component is re-rendered, but the lifecycle methods are not run"
(def a (r/atom 1))
(defn c []
(r/create-class
{:reagent-render
(fn []
(println "render c with " @a)
[:div @a])
:component-will-update
(fn [this] (println "will-update c"))
:should-component-update
(fn [this] (println "should-update c"))
:component-did-update
(fn [this] (println "did-update c"))}))
(r/render-component
[c]
(.getElementById js/document "app"))
(reset! a (rand-int 10))
;=> render c with 1
;=> will-update c
;=> render c with 6
;=> did-update c
this is triggering component-did-update, it should not accordingly to above paragraph
(def a (r/atom 1))
(defn c [x]
(r/create-class
{:reagent-render
(fn [x]
(println "render c with " x)
[:div x])
:component-will-update
(fn [this] (println "will-update c"))
:should-component-update
(fn [this] (println "should-update c") true)
:component-did-update
(fn [this] (println "did-update c"))}))
(defn cwrap [] [c @a])
(r/render-component
[cwrap]
(.getElementById js/document "app"))
(reset! a (rand-int 10))
;=> render c with 1
;=> should-update c
;=> will-update c
;=> render c with 2
;=> did-update c
So I guess the end result is, if the component doesn't get props (which is the first argument), component-will-receive-props
and should-component-update
is never called.
The piece of documentation you pasted is indeed a bit confusing. I'd recommend opening an issue in github, or asking their opinion in #re-frame
@mikethompson That was an excellent post and exactly what I needed. Thanks for writing it!
does anyone have experience with https://github.com/madvas/cljs-react-material-ui
@pbaille I think that documentation is out of date now
We've noticed the same thing
@danielcompton, ok great
@pbaille If you want to open a docs ticket that'd be awesome
@danielcompton ok I will
@danielcompton , done, but I don’t know how add the docs label
no worries, I think only committers can do that. Thanks!