Alessandro Casazza 6c060582ec
fix: Wishlist flow
2022-01-21 11:43:17 +01:00

21 lines
514 B
TypeScript

type Options = {
includeProducts?: boolean
}
export function emptyHook(options?: Options) {
const useEmptyHook = async ({ id }: { id: string | number }) => {
let wishlist = []
const localWishlist = localStorage.getItem('wishlist')
if (localWishlist) {
wishlist = JSON.parse(localWishlist)
wishlist = wishlist.filter((p: string) => p !== id)
}
localStorage.setItem('wishlist', JSON.stringify(wishlist))
return wishlist
}
return useEmptyHook
}
export default emptyHook