Say I have the following code:
import React, { memo } from 'react';
const MyComponent = ({ arrayOfStuff }) => (
<div>
{arrayOfStuff.map(element => (
<p key={element.foo}>element.foo</p>
))}
</div>
);
const areEqual = (prevProps, nextProps) => {
const prevArrayOfStuff = prevProps.arrayOfStuff;
const nextArrayOfStuff = nextProps.arrayOfStuff;
if (prevArrayOfStuff.length !== nextArrayOfStuff.length)
return false;
for (let i; i < prevArrayOfStuff.length && i < nextArrayOfStuff.length; ++i) {
if (prevArrayOfStuff[i].foo !== nextArrayOfStuff[i].foo)
return false;
}
return true;
};
export default memo(MyComponent, areEqual);
And suppose arrayOfStuff is pretty large, maybe hundreds of elements. Am I really saving much time memoizing the component? I would think that in the event the props are the same, it would iterate over all the elements regardless of the memo since both areEqual and the render function do so.