J
J
Jasulan982018-09-08 20:06:10
React
Jasulan98, 2018-09-08 20:06:10

How do I know that the data from the server has changed if I'm in another component?

I made a small project in which I used react, redux, redux thunk. When the user enters the application, all actions make asynchronous requests and replenish the reducer data. But when the data from the server changes regardless of the application, I must send the dispatch action before loading the component, otherwise the data does not change and it slows down. Calling action in Shouldcomponentupdate is also not an option. How will they notify that the data has changed and the reducer updated itself. PS

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima, 2018-10-12
@Jasulan98

You can check the data from the server, and compare with the current store (part of the store), and if they are not equal, dispatch the desired action.
To watch the store update, you can subscribe to it:

store.subscribe(() => {
       console.log(...)
    })

or better yet, use the chrome extension 'redux'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question