As a user, I have a wishlist feature on my website. Whenever I add items to my wishlist, they are stored in the localStorage. I also want to display the total number of items in my wishlist automatically without having to refresh the page.
Although the items are successfully added to the wishlist and displayed in the span tag, I encounter an issue in the console: Warning - Maximum update depth exceeded.
If anyone can provide assistance with this issue, it would be greatly appreciated. The code for this functionality is located in the Header component of the page.
/* Code for the Header component */
import React, { useContext, useState, useEffect } from 'react';
import { Container, Navbar, Nav } from 'react-bootstrap';
import { ThemeContext } from '../GlobalComponents/ThemeProvider';
import { BiSun, BiMoon, BiCart } from 'react-icons/bi';
// Other imports...
// Component definition...
In addition to the Header component, there is also a ProductCard page included below:
/* Code for the ProductCard component */
import React, { useState } from 'react';
import { Button, Card } from 'react-bootstrap';
import { useThemeHook } from '../GlobalComponents/ThemeProvider';
import { useCart } from 'react-use-cart';
import { BsCartPlus } from 'react-icons/bs';
// Other imports...
// Component definition...