I have this React.memo component that I want to render only if the props doesn't change with sending a second argument isEqual function. When I console.log the wrapper component and the memmoized component I can see that its being rendered with the same props.. What am I doing wrong?
My wrapper component
export const WrapperComponent= props => {
console.log('MemoizeComponent', props);
return (
<MemoizeComponent name="memo"/>
);
}
export const WrapperComponent;
My memmoized component
export const Component = props => {
console.log('component: ', props.name)
return (
<div>{props.name}</div>
);
}
function isEqual(prevProps, nextProps) {
console.log(prevProps.name);
console.log(nextProps.name);
return prevProps.name === nextProps.name;
};
export const MemoizeComponent = React.memo(Component, isEqual);
console output:
memo
memo
component:memo
memo
memo
component:memo
I want to render only if the props doesn't change with sending a second argument isEqual functionthat sounds like an opposite to whatReact.memodoes - prevent re-render if props didn't change. - Clarity