-
-
Notifications
You must be signed in to change notification settings - Fork 350
Make shouldComponentUpdate optimalization optional #18
Comments
Hmm hard to form an opinion about it as the best practice seems to be in flux about this currently? Especially since they seem to want to move away from context in React-Router if I understand it correctly? Note that you can still implement your own But if there is no convenient way around this issue I can add an option for it. Do you have a suggested syntax? |
OK, I took a closer look a the facebook issue and currently there seems now way to cleanly handle it, as it is not possible to detect context changes on components that don't use the context themselves, so As mentioned in the original issue You could define your own I think in general the only clean solution to this now is make context objects singletons to which one can subscribe manually as suggested by Dan Abramov in the beginning of the thread. |
As a temporary solution I monkey patched let observer = require('mobservable-react').observer;
let React = require('react');
require('mobservable-react').observer = function (componentClass) {
if (componentClass.prototype.render) {
let target = componentClass.prototype || componentClass;
if (!target.shouldComponentUpdate) {
target.shouldComponentUpdate = () => true;
}
}
return observer(componentClass);
}; In my specific issue problem was not limited to |
There is a known issue facebook/react#2517 when shouldComponentUpdate prevents rerendering children components depended on the context. It would be nice to make this optimalization optional for compatiblitiy with non reactive libs e.g react-router and it's Link component (applying active link style depends on the context).
The text was updated successfully, but these errors were encountered: