From 4574bedb0f8b254b388cfd57bc6aefa820e712e2 Mon Sep 17 00:00:00 2001 From: Mykhailo Pogorenyi Date: Wed, 20 Dec 2023 18:40:52 +0200 Subject: [PATCH] fix buttons fix add to cart and favorites buttons --- src/modules/shared/AddToCart/AddToCart.tsx | 6 +- .../AddToFavourites/AddToFavourites.tsx | 96 +++++++------- src/store/reducers/cartSlice.ts | 125 +++++++++--------- 3 files changed, 120 insertions(+), 107 deletions(-) diff --git a/src/modules/shared/AddToCart/AddToCart.tsx b/src/modules/shared/AddToCart/AddToCart.tsx index 10fb63e..c87e2e6 100644 --- a/src/modules/shared/AddToCart/AddToCart.tsx +++ b/src/modules/shared/AddToCart/AddToCart.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import cn from 'classnames'; import styles from './AddToCart.module.scss'; @@ -29,6 +29,10 @@ export const AddToCart: React.FC = ({ productItem }) => { } }; + useEffect(() => { + setIsSelected(cart.some((cartItem) => cartItem.id === productItem.id)); + }, [cart, productItem.id]); + return (