-
-
Save ablamunits/ff7888ae1dc40b014c4f4e5a195a9522 to your computer and use it in GitHub Desktop.
VOC - ex2
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
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