Skip to content

Instantly share code, notes, and snippets.

@JonAbrams
Last active August 7, 2018 19:42
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 JonAbrams/f1f01c4965e33dbbc4d298b3ebb087c9 to your computer and use it in GitHub Desktop.
Save JonAbrams/f1f01c4965e33dbbc4d298b3ebb087c9 to your computer and use it in GitHub Desktop.
const handleRemove = ({ merge, space }, itemToBeRemoved) => {
merge({
items: space.items.filter(item => item !== itemToBeRemoved)
});
};
export const ShoppingCart = ({ space }) => (
<div>
<ul>
{space.items.map(item => (
<li key={item.uuid}>
<CartItem
space={item}
onRemove={space(handleRemove).bind(null, item)}
/>
</li>
)}
</ul>
</div>
);
const CartItem = ({ space, onRemove }) => (
<div>
<strong>{space.name}</strong>
<input
type="number"
min="0"
max="10"
onChange={space('count')}
value={space.count}
/>
<button onClick={onRemove}>Remove</button>
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment