Skip to content

Anti-pattern: creating store in render() #287

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
gaearon opened this issue Jul 17, 2015 · 2 comments
Closed

Anti-pattern: creating store in render() #287

gaearon opened this issue Jul 17, 2015 · 2 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented Jul 17, 2015

I've seen people do that several times. It's an easy mistake to make because <Provider>'s hot reloading capabilities also mean you can replace store at any time with a new object, and it'll transfer the state behind the scenes.

However this is wasteful performance-wise and can lead to weird issues. Can we somehow prevent people from creating the store inside render method?

@gaearon
Copy link
Contributor Author

gaearon commented Jul 19, 2015

We can probably warn inside react-redux/Provider#componentWillReceiveProps if the store is replaced but we're in production mode.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 31, 2015

This will probably be solved by another approach to hot reloading in #350.
Closing for now.

@gaearon gaearon closed this as completed Jul 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant