im trying to run this code for cart details and i got an error, yet i couldnt obtain the result due to the error above,the error points directly to the (cartDetail.map )The code looks correct but coulnt figure out where the error is. id like anyone to assist with a fix.
useEffect(() => {
let cartItems = [];
if (props.user.userData && props.user.userData.cart) {
if (props.user.userData.cart.length > 0) {
props.user.userData.cart.forEach(item => {
cartItems.push(item.id)
});
dispatch(getCartItems(cartItems, props.user.userData.cart))
.then((response) => {
if (response.payload.length > 0) {
calculateTotal(response.payload)
}
})
}
}
}, [props.user.userData])
const calculateTotal = (cartDetail) => {
let total = 0;
cartDetail.map(item => {
total += parseInt(item.price, 10) * item.quantity
});
setTotal(total)
setShowTotal(true)
}