Skip to content

Instantly share code, notes, and snippets.

@ablamunits
Created June 17, 2020 14:07
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/137238dff4ed2c9f8beb663a1f64d359 to your computer and use it in GitHub Desktop.
Save ablamunits/137238dff4ed2c9f8beb663a1f64d359 to your computer and use it in GitHub Desktop.
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