Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Created November 21, 2021 22:34
Show Gist options
  • Save BrianJenney/bd838165e0e990c00f9ad539aa28fe15 to your computer and use it in GitHub Desktop.
Save BrianJenney/bd838165e0e990c00f9ad539aa28fe15 to your computer and use it in GitHub Desktop.
const Cart = ({items}) => {
const dispatch = useDispatch()
const isLoggedIn = useSelector((state) => state.account.isLoggedIn)
const clearCart = () => {
dispatch(reduxActionToClearCart())
}
if(!isLoggedIn){
return <LoginPrompt/>
}
return(
<div>
<div>
{items.map(({price, name}) => {
return(
<ItemDisplay price={price} name={name}/>
)
})
<button onClick={() => clearCart()}>Clear Cart</button>
</div>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment