-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Do I need connect() from React Redux or should I use store.subscribe()? #281
Comments
This is a good example to understand how React Redux works, but I wouldn’t do this in a real app.
Yes, this is precisely how React works: you must tell it that the state has updated.
One issue you have there is that you never unsubscribe. You should be unsubscribing in
Yes. You don't implement any optimizations. For example, components generated by Have a look at I was a guest at this readthesource episode explaining how React Redux works so you might want to check it out. We definitely recommend using React Redux for best performance instead of rolling your own subscription logic. |
Thanks @gaearon. This was extremely helpful. Have a nice weekend. |
Greetings to all of you seasoned Redux veterans!
I'm new to React and Redux but I'd like to get this stuff right before moving on with our project. I've read about connecting presentational and container components but before going there, I'd like to make a simple component that does it all. I have a
Header
component that should render user's username if user is authenticated. I already managed to successfully login the user using our API and update my immutable Redux store accordingly. So, looking from the surface, the following code works.The question is whether the following implementation is an antipattern or otherwise 'bad' e.g. performance-wise? Am I allowed to call
setState()
manually when using Redux? Without thesetState()
call the component doesn't seem to recognise state changes in store at all. Is there performance (or some other relevant) differences between this implementation strategy and the one that usesmapStateToProps()
method withconnect()
?The text was updated successfully, but these errors were encountered: