You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, it returns true when the component should update (something has changed), and false otherwise. On the other hand, shallowEqualState and shallowEqualWithoutReactElements both work in the opposite way: they return false when there's a change (something has changed), and true otherwise.
That said, shouldn't shallowEqual use logical AND instead of OR in its body? E.g.:
This way, if shallowEqual returns true, it means that the props/state are equal and that the component should not update. Whereas, if it returns false, it would mean that something has changed and the component should update.
And then, someone using shallowEqual would have to negate it in order to know that something has changed and therefore a component should update:
...
if (!super.shouldComponentUpdate || super.shouldComponentUpdate(nextProps, nextState)) {
shouldUpdate = !shallowEqual(this.props, nextProps, this.state, nextState); // If shallowEqual returns `false`, it means that the prev props or state are not equal to the next props or state and we should therefore update...
}
...
What do you think?
The text was updated successfully, but these errors were encountered:
Hi and thank you for this HOC. I also read your article https://medium.com/myheritage-engineering/how-to-greatly-improve-your-react-app-performance-e70f7cbbb5f6
which has been pretty helpful.
I only have one question regarding the
shallowEqual
function:Right now, it returns
true
when the component should update (something has changed), andfalse
otherwise. On the other hand,shallowEqualState
andshallowEqualWithoutReactElements
both work in the opposite way: they returnfalse
when there's a change (something has changed), andtrue
otherwise.That said, shouldn't
shallowEqual
use logical AND instead of OR in its body? E.g.:This way, if
shallowEqual
returnstrue
, it means that the props/state are equal and that the component should not update. Whereas, if it returnsfalse
, it would mean that something has changed and the component should update.And then, someone using
shallowEqual
would have to negate it in order to know that something has changed and therefore a component should update:What do you think?
The text was updated successfully, but these errors were encountered: