- Forums
- react
- React Avoid And Stop Too Many Re-renders In Your Application
react avoid and stop Unexpected Application Error! Too many re-renders. React limits the number of renders to prevent an infinite loop. [5240], Last Updated: Mon Jun 24, 2024
edw
Sun Dec 03, 2023
0 Comments
184 Visits
As a React developer, I run into this the too many re-renders error every so often. Not as much now as I did when I started developing React applications. My notes helped me find the solutions to this error, so these are my notes and examples:
1. Onclick:
If you are using onlclick, be sure to use an arrow function, change:
From:
onClick={setEditForm(!editForm)}
To:
onClick={()=>setEditForm(!editForm)
2. UseEffect()
UseEffect() can re-render only when a condition has been changed.
useEffect(() => {
}, [editForm])