Why does this work for the onClick
const mapDispatchToProps = (dispatch) => ({
toggleCartHidden: () => dispatch(toggleCartHidden()),
});
<Button
onClick={() => {
history.push('/checkout');
toggleCartHidden();
}}
>Button text</Button>
But this doesnt work (the routing doesnt work)
<Button
onClick={
(() => {
history.push('/checkout');
},
toggleCartHidden)
}
>Button text</Button>
I have another component with similar code that works with this syntax with onClick (no function call within onClick)
const mapDispatchToProps = (dispatch) => ({
toggleCartHidden: () => dispatch(toggleCartHidden()),
});
<div className='cart-icon' onClick={toggleCartHidden}> ICON </div>