TechnicalCollectible prompt

Fix a React infinite re-render or useEffect loop

Stop a component that renders forever or refetches nonstop by finding the value that changes every time.

CursorClaude CodeCodex

Curated by Nvoka

Nvoka wordmark logo
Nvoka wordmark logoTechnical

Fix a React infinite re-render or useEffect loop

Act as a senior React engineer. A component in my {{tech_stack}} app is stuck in a loop: the console says Too many re-renders or Maximum update depth exceeded, the page freezes, or the network tab shows the same request firing nonstop. Here's the error, then the component: {{error_message}} {{code}} Gather evidence first: - The component named in the stack trace, and which effect or state setter runs repeatedly (temporary logs with a counter are fine) - In the network tab, how often the request repeats - The React DevTools Profiler, with recording of why each component rendered turned on, to see which prop or state changes every time Likely causes for this symptom, most common first: 1. An effect that sets state it also depends on, such as fetching data and saving it with that data in the dependency list 2. A dependency that's a new object, array or function on every render, such as an inline options object or a callback defined in the component 3. Calling a state setter during render, or giving onClick a function call instead of a function 4. A parent re-creating a prop every render that a child's effect depends on 5. Two effects, or state and a URL parameter, updating each other back and forth 6. Strict Mode running effects twice in development, which is expected and isn't a loop Confirm which value changes, then make the smallest fix: compute derived values instead of storing them in state, depend on a stable primitive such as an id, memoize only what is truly a dependency, or move fetching to the project's data-fetching library. Don't silence the hooks lint rule or drop dependencies to make it stop. Add a test that renders the component and asserts the request fires once, and explain the loop in plain words.
Technicalnvoka.com/library/nvoka-fix-a-react-infinite-re-render-or-effect-loopScan to open
Technical

Fix a React infinite re-render or useEffect loop

Stop a component that renders forever or refetches nonstop by finding the value that changes every time.

Nvoka logo

Curated by Nvoka

CursorClaude CodeCodexGitHub Copilot
Add to my library

Make it yours

Fill in the blanks and change any word. Only your copy changes, never the card.

Fill in the blanks

0 of 3 filled

Your prompt

Act as a senior React engineer. A component in my {{tech_stack}} app is stuck in a loop: the console says Too many re-renders or Maximum update depth exceeded, the page freezes, or the network tab shows the same request firing nonstop. Here's the error, then the component: {{error_message}} {{code}} Gather evidence first: - The component named in the stack trace, and which effect or state setter runs repeatedly (temporary logs with a counter are fine) - In the network tab, how often the request repeats - The React DevTools Profiler, with recording of why each component rendered turned on, to see which prop or state changes every time Likely causes for this symptom, most common first: 1. An effect that sets state it also depends on, such as fetching data and saving it with that data in the dependency list 2. A dependency that's a new object, array or function on every render, such as an inline options object or a callback defined in the component 3. Calling a state setter during render, or giving onClick a function call instead of a function 4. A parent re-creating a prop every render that a child's effect depends on 5. Two effects, or state and a URL parameter, updating each other back and forth 6. Strict Mode running effects twice in development, which is expected and isn't a loop Confirm which value changes, then make the smallest fix: compute derived values instead of storing them in state, depend on a stable primitive such as an id, memoize only what is truly a dependency, or move fetching to the project's data-fetching library. Don't silence the hooks lint rule or drop dependencies to make it stop. Add a test that renders the component and asserts the request fires once, and explain the loop in plain words.
See all