-
-
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
Suggestion: @connect's shouldComponentUpdate could be optional or opt-in #88
Comments
Fair. I'm open to opt-out behavior with a |
@dallonf yup this is a tricky situation. My thought is that in keeping with the paradigm that redux assumes state is not mutated we should guide people towards making more pure Components and leave the aggressive Given that you won't always have control over this situation though i think there are a couple of workarounds that might be worth exploring (some more hack-ish than others). I haven't tried any of these but in theory they should work
maybe something like this
btw, i never actually use forceUpdate so not sure if it would need to go there or in componeDidUpdate or somewhere else but essentially this should force the connected component to update on every prop change you would use it like this
|
dealing with a second arg of an object of functions complicates this slightly but yeah this solution is certainly workable. |
Cool, I'll see if I can add an options argument (defaulting to |
Sounds good. |
FYI to anyone looking at this issue, the Also, after diving into the implementation of a Anyways, I've got a PR incoming soon. |
The
@connect
decorator, by default, appears to add a very aggressiveshouldComponentUpdate
hook to the decorated component. This is great if Redux and props are the only sources of statefulness in your app - but that's not always true and leads to some seriously confusing behavior with non-obvious workarounds when it's not.This is a known issue, of course, with react-router 0.13, but I'm having the same issue with react-intl's
IntlMixin
, which adds localization data to context. And I get the feeling that this is going to keep happening as long as the React ecosystem is as fragmented as it is right now.It would be really nice to just be able to throw an option on the
@connect
ed components that I know are impure (or, similar to React core'sPureRenderMixin
, throw an option on the ones I know are pure; there's certainly room for debate as to whether opt-in or opt-out is the right choice here).The text was updated successfully, but these errors were encountered: