Last active
May 10, 2020 14:41
-
-
Save Silverwolf90/65c225aa8984f53aee273e3cb22373cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Is this possible to do? | |
const ListComponent = ({ items, Actions }) => ( | |
<ul> | |
{items.map(item => ( | |
<li key={item.id}> | |
{item.name} <Actions item={item} /> | |
</li> | |
))} | |
</ul> | |
); | |
const ListContainer = ({ items }) => { | |
const [selected, setSelected] = useState(); | |
const Actions = useCallback( | |
({ item }) => { | |
const [clicked, setClicked] = useState(false); | |
const handleClick = useCallback( | |
() => { | |
setClicked(true); | |
setSelected(item); | |
}, | |
[item] | |
); | |
return ( | |
<button onClick={handleClick}> | |
{clicked ? 'Clicked' : selected ? 'Selected' : 'Select'} | |
</button> | |
); | |
}, | |
[selected] | |
); | |
return ( | |
<> | |
{selected.name} | |
<ListComponent items={items} Actions={Actions} /> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment