Alessandro Casazza 93d5fc0220
feat: Add wishlist
2022-01-21 11:43:16 +01:00

21 lines
523 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 Promise.resolve()
}
return useEmptyHook
}
export default emptyHook