#issue 1 was missing dependency: "emptyShoppingCart"
const { emptyShoppingCart } = useContext(CartContext)
useEffect(() => {
if (oobCode) {
setOrderId(oobCode)
emptyShoppingCart()
}
}, [oobCode])
so change to
fix:
useEffect(() => {
if (oobCode) {
setOrderId(oobCode)
emptyShoppingCart()
}
}, [oobCode, emptyShoppingCart])
now #issue 2 is rendered forever because emptyShoppingCart always re-create
fix: useCallback
const emptyShoppingCart = useCallback(() => {
setShoppingCart([])
setListingId('')
}, [])
Comments
Post a Comment