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

23 lines
575 B
TypeScript

import { useCallback, useMemo } from 'react'
export function emptyHook() {
const useEmptyHook = async (options: any = {}) => {
let wishlist = []
const localWishlist = localStorage.getItem('wishlist')
if (localWishlist) {
wishlist = JSON.parse(localWishlist)
if (!wishlist.includes(options.productId)) {
wishlist.push(options.productId)
}
} else {
wishlist.push(options.productId)
}
localStorage.setItem('wishlist', JSON.stringify(wishlist))
return wishlist
}
return useEmptyHook
}
export default emptyHook