javascript - 在 VS CODE TERMINAL 中有这个错误:Expected to return a value in arrow function array-callback-return
问题描述
我试图运行此代码以获取购物车详细信息,但出现错误,但由于上述错误,我无法获得结果,错误直接指向(cartDetail.map)代码看起来正确但无法确定错误在哪里. 我喜欢任何人来协助修复。
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)
}
解决方案
推荐阅读
- windows - 使用 robocopy 复制带空格的文件/文件夹太疯狂了
- python - Tensorflow中数据预处理过程中的问题
- python - 超时过期 pgadmin 无法连接到服务器
- sql - 如何选择一个表中存在但另一个表中不存在的值?
- spring - 没有在 WebStomp.connect 上调用带有 Spring Security ChannelInterceptor.presend 函数的 Spring WebSockets
- powershell - 将测试路径输出重定向到文本文件
- python - 有没有办法在python中安装包后下载包资源?
- mysql - mysql的日期时间值不正确
- java - 扫描仪使用循环从命令行读取文本文件,但循环不会中断
- python - django 创建客户端用户