Troubleshooting guide · React · Next.js · TypeScript
React & Next.js Errors: Causes and Fixes
Common React and Next.js errors with direct explanations and fixes, from the issues I repair in client web apps and AI-generated codebases.
By Muhammad Abdullah, full-stack, mobile and ai automation developer · Last reviewed
Error 01
“Too many re-renders” in React
Too many re-renders. React limits the number of renders to prevent an infinite loop.Short answer
A state update runs during render, which triggers another render, forever. The usual cause is calling a setter directly in JSX, like onClick={setOpen(true)}, instead of passing a function.
Error 02
Next.js “Hydration failed” / text content does not match
Hydration failed because the server rendered HTML didn't match the clientShort answer
The HTML rendered on the server differs from the first render in the browser. Remove browser-only or time-dependent values from the initial render, and fix invalid HTML nesting.
Error 03
“Each child in a list should have a unique key prop”
Each child in a list should have a unique "key" prop.Short answer
Items rendered with .map() need a stable, unique key so React can track them. Use an id from your data; avoid array indexes when items can be added, removed or reordered.
Error 04
“Cannot update a component while rendering a different component”
Cannot update a component (`X`) while rendering a different component (`Y`)Short answer
A child component calls a parent’s state setter during its render. Move that call into an event handler or a useEffect.
Error 05
Next.js: “needs useState … only works in a Client Component”
You're importing a component that needs useState. This React Hook only works in a Client Component.Short answer
In the Next.js App Router, components are Server Components by default and cannot use hooks or browser APIs. Add "use client" at the top of the file that uses them, and keep that client component as small as possible.
Error 06
“Objects are not valid as a React child”
Objects are not valid as a React child (found: object with keys {…})Short answer
You are rendering a whole object (or a Date, or a Promise) in JSX. Render a specific field, format the value as a string, or map an array to elements.
Error 07
Next.js “Module not found: Can't resolve 'fs'”
Module not found: Can't resolve 'fs'Short answer
Server-only Node.js code (fs, path, database clients) is being bundled into browser code. Move it to a Server Component, a Route Handler or a server action, and import it only from server files.