type merchandiseProps = {
merchandises: merchandiseType[];
cart?:string,
collection?:string,
fallbackData?: any
};
const MerchandiseList: FC<merchandiseProps> = ({ merchandises }) => {
const [cart, setCart] = useState<merchandiseType[]>(
typeof window !== undefined ? JSON.parse(localStorage.getItem("collection") || "[]") : ''
);
const [wishlist, setWishlist] = useState<merchandiseType[]>(
JSON.parse(localStorage.getItem("collection") || "[]")
);
useEffect(() => {
localStorage.setItem("cart", JSON.stringify(cart));
localStorage.setItem("collection", JSON.stringify(wishlist));
}, [cart, wishlist]);
const addToCart = (item: merchandiseType) => {
setCart([...cart, item]);
};
const addToCollection = (item: merchandiseType) => {
setWishlist([...wishlist, item]);
};
I'm trying to use typeof window but facing issues. Seeking assistance..................