Answer the question
In order to leave comments, you need to log in
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
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(...)
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question