Reputation: 381
I am coming from the world of SPA's and REST/GraphQl API's. Now I am building personal project with Next.js library for SSR(Server Side Rendered) React App.
Since I used Redux in all of my single page Apps, I'm now wondering how should I manage user state when every route user visits, a new link is loaded and the page has been refreshed.
I found some info about sessions and cookies, but neither of those are familiar to me. I looked at some online articles about using Redux with Next.js but it seems complicated.
Upvotes: 27
Views: 31022
Reputation: 654
If you're used to doing it in a route-based way, this may help understand:
Provider
for redux, so all pages
and components in the app can access the store
.otherwise different user data can be mixed up. On the client side the same store is used, even between page changes.```
req
uest, the url
, and possibly even the res
ults (of the request) into the initial state of the store
, so each page and component can utilize the store
before rendering.getInitialProps
which will perform some sideEffect before the components on a page renders, and provide data to the page's props.Upvotes: 2
Reputation: 35553
Let's simplify how Next works, browser sends a request to the server, Next renders on server side, returns an html, then, Next re-hydrate the page, and from now it behaves as SPA.
Next has an example folder basically for every technology including redux
.
Checkout the redux example.
Upvotes: 11