-
-
Save ablamunits/137238dff4ed2c9f8beb663a1f64d359 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
function ShoppingForm() { | |
const [shoppingItems, setShoppingItems] = useState(['Apples', 'Cookies']); | |
return ( | |
<InputWithLabels | |
value={shoppingItems} | |
onChange={setShoppingItems} | |
/> | |
) | |
} | |
function InputWithLabels(props) { | |
const onAddItem = (itemToAdd) => { | |
props.onChange([...shoppingItems, itemToAdd]); | |
}; | |
const onRemoveItem = (itemToRemove) => { | |
const updatedItems = shoppingItems.filter(item => item !== itemToRemove); | |
props.onChange(updatedItems); | |
} | |
const onClickClearAll = () => { | |
props.onChange([]) | |
} | |
// Your own implementation of this component. Go wild! | |
return ( | |
<div> | |
{props.value.map((label) => renderLabel(label))} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment