Fork me on GitHub

Why we can't do this to update Component:

(def content (r/atom 0))
(js/setInterval (fn []
                  (swap! content inc)
                  (println @content)) 1000)

(defn home []
  [:> rn/View {:style (styles :container)}
       [:> rn/Text @content]])
If I try to define atom in global, any update will invalid.

Lone Ranger15:08:08

do you mean to be updating this every second or just once?

Lone Ranger15:08:29

I don't know what rnView or rn/Text are... what are those? is that react-native?


I had the same issue, solved using reagent lifecycles


@UJ9KCME4U t's a good solution. I also get it in reagent docs, we can do as official suggestions to avoid some problems.


What's the meaning of But ... when the re-render occurs because an input ratom changed, Lifecycle functions are not run. in

Lone Ranger15:08:43

in React there are things called life-cycle methods ( Normally, life-cycle methods are called in a certain order

Lone Ranger15:08:37

componentWillMount, componentDidMount, shouldComponentUpdate, componentWillUpdate, renderComponent, componentDidUpdate, componentWillUnmount, componentDidUnmount

Lone Ranger15:08:45

that's the usual lifecycle

Lone Ranger15:08:09

what he's saying is that if the props change, only renderComponent will run and the rest of the lifecycle methods will be ignored


@U3BALC2HH Thanks for your answer, I will try it to test.

David Pham22:08:53

Anyone could provide me some insight on how to use js react components that uses the context API in reagent? I always get that this.context.localize does not exists. For the record I am trying to adapt this example:

David Pham22:08:37

In clojurescript