Suppose I have these React components:
const Compo1 = ({theName}) => {
return (
<Nested foo={() => console.log('Dr. ' + theName)}/>
);
};
const Compo2 = ({theName}) => {
function theFoo() {
console.log('Dr. ' + theName);
}
return (
<Nested foo={theFoo}/>
);
};
And the nested component, wrapped in memo:
const Nested = React.memo(({foo}) => {
return (
<Button onClick={foo}>Click me</Button>
);
});
Function passed in foo is always recreated in Compo1 and also Compo2, correct?
If so, since foo receives a new function every time, does it mean memo will be useless, thus Nested will always be re-rendered?