I am trying to do some kind of online shop for myself and I got a problem.
I want to render my shopping cart size in the NavBar
component (which is on every page).<
In the dependency array you need to pass only the name of the function, just like below:
useEffect(() => {
setCount(getTotalCount());
console.log('count useEffect');
}, [getTotalCount]); // not like => getTotalCount()
The code was calling also the function like getTotalCount()
but only the name is needed, you don't need to call that.
I hope that helps!