This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-05
Channels
- # aws (1)
- # beginners (57)
- # boot (3)
- # cider (6)
- # clara (49)
- # cljs-dev (47)
- # cljsjs (23)
- # clojure (144)
- # clojure-dev (2)
- # clojure-finland (1)
- # clojure-germany (1)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (245)
- # clojurescript (39)
- # core-async (3)
- # cursive (6)
- # datomic (117)
- # emacs (3)
- # fulcro (6)
- # hoplon (10)
- # jobs (7)
- # juxt (5)
- # leiningen (11)
- # om (27)
- # pedestal (4)
- # perun (2)
- # re-frame (22)
- # reagent (35)
- # ring-swagger (11)
- # shadow-cljs (333)
- # spacemacs (10)
- # specter (10)
- # sql (20)
- # vim (8)
@rnagpal that's not enough information to go on
What more information should I add @pesterhazy
why do you assume that component-will-receive-props will be called?
do you actually change the props?
Here is the code
(fn [opts]
(let [data-sub (re-frame/subscribe [::data-sub])
show-loading? (reagent/atom false)]
(reagent/create-class
{:display-name "generic-loading-component"
:component-did-mount
(fn component-did-mount [_]
(js/console.log "In component-did-mount of loading")
(when-not @show-loading?
(js/setTimeout #(when-not @node-events
(reset! show-loading? true))
100)))
:component-will-receive-props
(fn component-will-receive-props [_]
(js/console.log "In component-will-receive-props of loading")
(when @node-events
(js/console.log "reset show loading to false")
(reset! show-loading? false)))
:component-will-update
(fn component-will-update [_]
(js/console.log "In component-will-update of loading")
(when @node-events (js/console.log "reset show loading to false")
(reset! show-loading? false)))
:reagent-render
(fn [opts]
(js/console.log "In Render of loading")
(if @show-loading? [:div "LOADING"]
[show-data @data-sub opts]))})))
yeah looks like you're not actually changing the props, opts
for background, there are three ways to cause a component to rerender in React
1. this.state 2. this.props 3. manually calling render on the component again
Reagent typicaly doesn't use 1; 2 is pretty obvious
If you change a ratom, reagent does 3
yes it's still a lifecycle change, but comoponent-will-receive-props won't be called
component-will-update should be called though
one trick is to use an outer comp/inner comp pattern
you'd pass the changes to the inner component, which then gets an explicit prop change
another option is to inspect your ratom in component-will-update
depends on what you want to achieve really
@pesterhazy can you please point me to the source code that is responsible for updating the component based on subscription
I think it's here: https://github.com/reagent-project/reagent/blob/master/src/reagent/impl/component.cljs#L140
it's a batch/queue-render
call wrapped in a Reaction
this enqueues the component to be re-rendered at a later point, e.g. at the next tick
Thanks a lot @pesterhazy. Going through the code now
it's a bit cryptic 🙂