Fork me on GitHub
#reagent
<
2019-08-23
>
Aklscc05:08:04

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.

unbalanced15:08:08

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

unbalanced15:08:29

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

Vachi00:08:19

I had the same issue, solved using reagent lifecycles

Aklscc07:08:38

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

Aklscc10:08:19

What's the meaning of But ... when the re-render occurs because an input ratom changed, Lifecycle functions are not run. in https://github.com/reagent-project/reagent/blob/master/doc/WhenDoComponentsUpdate.md#lifecycle-functions

unbalanced15:08:43

in React there are things called life-cycle methods (https://programmingwithmosh.com/javascript/react-lifecycle-methods/) Normally, life-cycle methods are called in a certain order

unbalanced15:08:37

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

unbalanced15:08:45

that's the usual lifecycle

unbalanced15: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

Aklscc07:08:47

@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