-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
Reference Equality Check before setState() #1437
Comments
This would be more relevant for /~https://github.com/reactjs/react-redux but I’ll answer here. We can’t check it reliably before because we don’t want to call Since we can’t bail out early, we do some easy bail outs in
Now that I think of it we can probably do this as an optimization when neither |
We can discuss in reduxjs/react-redux#300. |
This is now fixed in the common case in |
Can you please detail what you mean by a "constant element"? |
We save the previous return value of |
Correct me if I'm wrong.
I noticed in Connect component's handleChange() method, each time store state changes, the setState() method is triggered. So each time the store state changes, all mounted container component generated by Connect() will fire setState(), and in turn, shouldComponentUpdate() would be called, and as long as store state changes, render() will be called.
I wonder if we can do a "reference equality check" before setState() is called. Would this eliminate many unnecessary calls to render() and improve performance?
My understanding is the setState() is designed for UI's local state, not the global state change irrelevent to this component. So that any state change will trigger all container component's method should be avoided.
The text was updated successfully, but these errors were encountered: