I have tried to remove the product from the cart. here the cart is an array that contains products in the object. when I try to filter the cart in reducer it returns proxy and cannot do filtering while in same thing doing in normal redux do filtering.
reducer function
const initialState = {
products: [],
cart: []
};
removeFromCart: (state, action) => {
return {
...state,
products: [...state.products],
cart: [state.cart.filter((prod) => prod != action.payload)]
};
};
remove from cart button
<button
onClick={() => dispatch(removeFromCart(productData))}
class="btn btn-danger"
disabled={stock < 1 ? true : false}
>
Remove from cart
</button>