Feature Request: Support custom equality checks
#319 aberto em 8 de mai. de 2025
Description
My app makes heavy use of custom equality checks for props and state via shouldComponentUpdate for class components and the arePropsEqual argument of React.memo for function components.
When I first tried out why-did-you-render I got a lot of notifications of props changing that were deeply equal that I knew were not actually causing re-renders (the components are re-rendering, but due to other reasons) because they have custom equality checks.
For now I've just patched why-did-you-render in logDifference to filter out differences that pass my custom equality check (if there's a .equals method on the object, I use that).
But I'd love it if there were support for custom equality checks. I think arePropsEqual should be possible to support automatically. shouldComponentUpdate is obviously more complicated, but I could imagine an advanced tracking setting that takes a callback:
static whyDidYouRender = {
arePropsEqual: (oldProps, newProps) => ... // comparison here
}
Technically there's already an escape hatch via a custom notifier but then you have to re-implement all of the default notifier logic yourself. I suppose an alternative solution would be to make the notifier exports more modular, such that filtering out differences is an easy thing to do without patching.