Skip to content

Instantly share code, notes, and snippets.

@Sergioamjr
Last active May 22, 2021 15:47
Show Gist options
  • Save Sergioamjr/a9df02d41962e3cb27b3b2b057d0a331 to your computer and use it in GitHub Desktop.
Save Sergioamjr/a9df02d41962e3cb27b3b2b057d0a331 to your computer and use it in GitHub Desktop.
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