Skip to content

add "Caveat" section to readme noting how you can't dispatch during componentWillMount on the server #726

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

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ If you are on an older version of React Native, you’ll need to keep using [Rea
We do a deep dive on how React Redux works in [this readthesource episode](https://www.youtube.com/watch?v=VJ38wSFbM3A).
Enjoy!

## Caveat

While peforming server-side rendering, if you dispatch actions during `componentWillMount` the resulting state will not render in the wrapped component, nor in parents or sibblings. The idiomatic approach to cover all environments is to only dispatch actions before your first render or in response to user-triggered events. During SSR use a routing mechanism based on the URL to dispatch actions on the store (and `await` on them if necessary) ***before*** calling `ReactDOMServer.renderTostring`. This is called "server-side pre-hydration."

You may want to checkout [Redux First Router](https://github.com/faceyspacey/redux-first-router) for a Redux-specific routing package that helps you resolve URL-driven *pre-hydration* on the server. Check the `thunk` option in their [server-rendering docs](https://github.com/faceyspacey/redux-first-router/blob/master/docs/server-rendering.md).

## License

MIT