Skip to content

Instantly share code, notes, and snippets.

@ablamunits
Created June 17, 2020 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ablamunits/ff7888ae1dc40b014c4f4e5a195a9522 to your computer and use it in GitHub Desktop.
Save ablamunits/ff7888ae1dc40b014c4f4e5a195a9522 to your computer and use it in GitHub Desktop.
VOC - ex2
function ShoppingForm() {
const [shoppingItems, setShoppingItems] = useState(['Apples', 'Cookies']);
const onAddItem = (itemToAdd) => {
setShoppingItems([...shoppingItems, itemToAdd]);
};
const onRemoveItem = (itemToRemove) => {
const updatedItems = shoppingItems.filter(item => item !== itemToRemove);
setShoppingItems(updatedItems);
}
const onClickClearAll = () => {
setShoppingItems([]);
}
return (
<InputWithLabels
value={shoppingItems}
onAddItem={onAddItem}
onRemoveItem={onRemoveItem}
onClickClearAll={onClickClearAll}
/>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment