Last active
May 22, 2021 15:47
-
-
Save Sergioamjr/a9df02d41962e3cb27b3b2b057d0a331 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
import { memo, useCallback } from "react"; | |
function ListItem({ item, onSelect }) { | |
return ( | |
<li> | |
<button onClick={() => onSelect(item)}>Select {item}</button> | |
</li> | |
); | |
} | |
const MemorizedList = memo(ListItem); | |
function MyList() { | |
const onSelectHandler = useCallback((selectedItem) => { | |
// Faz algo com selectedItem. | |
}, []); | |
return ( | |
<ul> | |
{array.map((e) => ( | |
<MemorizedList item={e} onSelect={onSelectHandler} /> | |
))} | |
</ul> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment