This is very simple, but it doesn’t seem to come up when I search.
If you a have a component rendered with React.memo
and are trying to figure out which prop is causing it to re-render:
;
… you can (ab)use React.memo
’s second parameter, propsAreEqual
.
/**
* Lets you skip re-rendering a component when its props are unchanged.
*
* @param Component — The component to memoize.
* @param propsAreEqual — A function that will be used to determine if the props have changed.
*/
The default propsAreEqual
argument compares each prop with Object.is
.
We’ll do the same but also log when a prop changes:
;
;
Now we’ll get log messages when a prop changes:
Δ bar
Easy!