Last active
December 22, 2023 17:14
-
-
Save vzaidman/ed64887a34c649b3ba5538074630f136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Main = React.memo(({onClick, style, children, items}) => { | |
const content = getContent({items}); | |
return ( | |
<div style={style} onClick={onClick}> | |
{content} | |
{children} | |
</div> | |
); | |
}) | |
export const App = () => { | |
return ( | |
<Main | |
// Main will always re-render because "style" is always | |
// a new object so *prevProps.style !== nextProp.style* | |
style={{width: '100%'}} | |
// Main will always re-render because "onClick" is always | |
// a new function so *prevProps.onClick !== nextProp.onClick* | |
onClick={() => console.log('click')} | |
// Main will always re-render because "items" is always | |
// a new array so *prevProps.items !== nextProp.items* | |
items={["a", "b"]} | |
> | |
{/* Main will always re-render because "children" is always a new */} | |
{/* React Element so *prevProps.children !== nextProp.children* */} | |
<div>hi!<div> | |
</Main> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment