Redux store not updating with SSR?
See original GitHub issueI’ve got a component where the store updates fine on the client side with the following code:
componentDidMount() {
const { loadQuoteIfNeededConnect, id } = this.props
loadQuoteIfNeededConnect(id)
}
If I comment that out and attempt to use the code below, the store does not update:
static async getInitialProps({ store, query: { id } }) {
// this fetches the data, but store is not updated
await store.dispatch(loadQuoteIfNeeded(id))
return { id }
}
I’ve got a console.log
directly above the return statement in my reducer, and I can see in my terminal that the data is in fact being fetched and returned properly with the code from getInitialProps()
, but the store is not updating.
Any ideas?
Issue Analytics
- State:
- Created 6 years ago
- Comments:35 (15 by maintainers)
Top Results From Across the Web
Next-Redux-Wrapper not updating SSR Store - Stack Overflow
I'm working on an app that uses SSR. It is based on React, Next, and Redux. I understand the general concept of having...
Read more >Why Redux Store Changes Don't Re-render - YouTube
When using Redux, it's common to run into issues where your store isn't updating, or isn't updating in the way you expect it...
Read more >Server Rendering - Redux - JS.ORG
On the client side, a new Redux store will be created and initialized with the state provided from the server. Redux's only job...
Read more >React State Not Updating Immediately? - Nate Gage - Medium
React State Not Updating Immediately? I'm setting state in my app and referencing it. Why don't I see the new values?
Read more >How to use Redux in Next.js - LogRocket Blog
Now we have successfully set up our Redux store. You can verify it by clicking the button, which will dispatch actions based on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my case it turns out I wasn’t returning the promise in my chain of dispatch functions. Working perfectly now!
For anyone else running into the same problem, here’s an example:
Component — using async/await
Actions — note that
loadQuoteIfNeeded()
has an implicit return andgetQuote()
is being returnedI have same issue, im using nextjs + redux toolkit I got the updated store on server, but i didnt get the store on client up to date like on server
Action
Store