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 (