bigcommerce / storefront-data-hooks

Hooks for React Storefront UI Components
MIT License
166 stars 36 forks source link

includeProducts in useWishlist() - not updating the data items after add/remove #108

Closed heylols closed 3 years ago

heylols commented 3 years ago

Previously I opened the ticket where the Wishlist does not contain the products : https://github.com/bigcommerce/storefront-data-hooks/issues/103

Right now, the issue is if I add or remove items in the wishlist, the items returned are not updating.

Eg:

const { data } = useWishlist({includeProducts : true })
console.log('included', data?.items)
// the items will not get updated after a adding/removing item to wishlist

But if I do not include the includeProducts parameter, the items are updating.

Eg:

const { data } = useWishlist()
console.log('included', data?.items)
// here items are seems to be updating
jorgemasta commented 3 years ago

Hey @heylols ,

this is similar to #89. We're using swr under the hook and useWishlist({includeProducts : true }) uses a different key than useWishlist().

When you use useAddItem() you're using the key used in useWishlist(). You have to use useAddItem({includeProducts : true }) to update useWishlist({includeProducts : true })

heylols commented 3 years ago

useWishlist({includeProducts : true })

Thanks mate!