VibeDict

🧩Endless redrawing (Too many re-renders)

What you'll see
Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

A value was changed while the screen was being drawn, so it kept redrawing and changing again, over and over without end.

🤔 Why does it happen?

  • Writing onClick={setOpen(true)} runs the function right away, before the button is even clicked
  • A value is changed inside useEffect, and every time that value changes, useEffect runs again

🔧 Try this

  1. Wrap it in an arrow function, like onClick={() => setOpen(true)}
  2. Check what's inside the [ ] (dependency array) at the end of useEffect

🤖 Ask your AI like this

I get the error below in React. Please find where the endless loop happens and fix it, and explain in simple words why it kept repeating. [Paste the full error here]

Replace the [ ] parts with your own situation, and paste the error with a few extra lines before and after it.

Related terms

Other errors in this group