首页 > 解决方案 > 在 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)
   }

标签: javascriptreactjsreact-reduxcart

解决方案


推荐阅读