79307209

Date: 2024-12-25 09:03:56
Score: 1
Natty:
Report link

in my understanding by default useEffect run once when the program run so when it run, the setItems change the value of items as you see :

useEffect(() => {
    setItems(getCart());
}, [items]);

and when the items change useEffect again run that creates a loop, to stop it remove the dependencies.

useEffect(() => {
    setItems(getCart());
}, []);
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Akanksha Verma