I'd like to have one prop in a component be an array of strings that is deep compared: <ChildComponent deepCompareThis={['a', 'b']} />
so I'd like to remove it from shallow comparison, as this array will always fail shallow comparison. I would like to keep this syntax for readability. I am using function components, so using React.memo
.
I am curious if there is a clean way to use React.memo
and deep compare one prop, while falling back to React's own default https://github.com/facebook/react/blob/master/packages/shared/shallowEqual.js
for everything else.
Edit: looking at shallowCompare, it seems as long as you use Object.is
for your other props values you should have the same comparison function. Perhaps it's not as scary as I thought to copy the comparison function. Most of it is optimization!