Reputation: 390
I am using redux to update the cart when a user clicks the add to cart button. The data which I am dispatching is not getting received instead different array of unknown values in received when I console.log it. Below is my dispatch function
const mapDispatchToProps = (dispatch) =>{
return {
addItemsToCart:(name) =>dispatch({type:'ADD_TO_CART',payload:name})
}
}
this is the button handling the dispatch. it updates the count of the cart icon but can't pass the data to the cart screen.
<Button icon="cart" mode="contained" onPress={(name) =>this.props.addItemsToCart(name)} style={styles.btn}>
Upvotes: 0
Views: 525
Reputation: 22726
considering you have some UI for cell or view as follow,
const renderCell = ({item}) => {
const {name} = item;
return (
//Your Item UI
<Button icon="cart" mode="contained" onPress={() =>this.props.addItemsToCart(name)} style={styles.btn}>
)
}
Considering your item has name than you can access like the way I have mentioned. If you still have issue please post your whole code which contains your button.
Upvotes: 1
Reputation: 751
There's somewhat lack of information, but I would assume that you're missing also an API request, that would put products into your shopping cart.
You're only updating local state with redux, that's why your application "knows" the new amount of items in the shopping cart. But you need also tell your backend that new items were added.
I'm pretty sure, when you get to shopping cart, it fetches data from the backend, not from redux.
Upvotes: 0