【发布时间】:2022-09-24 01:46:44
【问题描述】:
有时当我尝试将 2 个元素添加到购物车时我遇到了这个问题,但是如果我刷新并尝试做同样的事情,这个错误不会出现:
Unhandled Runtime Error
TypeError: Cannot read properties of undefined (reading '_id')
context\StateContext.js (17:61) @ eval
15 |
16 | const onAdd= (product, quantity) => {
> 17 | const checkProductInCart = cartItems.find((item) => item._id === product._id );
| ^
18 |
19 | setTotalPrice((prevTotalPrice) => prevTotalPrice + product.price * quantity );
20 | setTotalQuantities((prevTotalQuantities) => prevTotalQuantities + quantity );.
【问题讨论】:
-
请提供足够的代码,以便其他人可以更好地理解或重现该问题。
标签: javascript reactjs e-commerce