Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.