Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
memo equality check function overrides state #14972
Do you want to request a feature or report a bug?
What is the current behavior?
What is the expected behavior?
Reproduction and detailed explanation of the bug is within this codesandbox:
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Note: I spent few hours verifying that this is a genuine bug and not a due to my misunderstanding, but I apologize if it is the latter.
Custom equality checks must include all props you care about. Including callbacks. (This is why generally you shouldn't supply your own comparison function — it's easy to make a mistake!)
The mistake you're making is that you're ignoring changes to
If I fix your equality function, it works:
const equalityCheck = (prevProps, nextProps) => - prevProps.comparedProp === nextProps.comparedProp; + prevProps.comparedProp === nextProps.comparedProp && + prevProps.onSelect === nextProps.onSelect;
You can also
The most idiomatic fix to this is