-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Redux) Script tag with window.__INITIAL_STATE__ = { ... } in html response from server #467
Comments
If my aim isn't clear please let me know and I will prepare a code example. |
We already do this in the Redux Example guide: https://github.com/zeit/next.js/wiki/Redux-example |
You don't need to use a global variable because |
YeaaahhH! Thx for your answer. The redux example doesn't include the data fetching part and I didn't get that the |
First of all, thank you for creating such a nice framework, it works like a charm.
I am writing a website with
next.js
andRedux
. I usegetInitialProps
to preload data from thecontentful
API. If I get this right, this function is first called once on the server, then my App is beeing rendered with the preloaded data and the response is retrieved with the full rendered html. Finally on the client side,getInitialProps
is executed again. There, it fetches my preloaded data again and initializes the store to be handled there.I was just wondering if there was a way to avoid the first client-side request when executing
getInitialProps
by allowing to expose the initial Redux state in a script tag when retrieving the rendered html from the server. Like this:Doing this would allow me to use this global variable as an initial state in the store creation on the client side after the first load. After that, when navigating with the
<Link />
component, thegetInitialProps
would be executed again and I would check if window.store is already existing. If so, I would skip the data fetching.Does it make sense to you? Is there a way to access the rendered html output before it is sent to the browser and to extend it?
The text was updated successfully, but these errors were encountered: