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.
The text was updated successfully, but these errors were encountered:
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