Skip to content

React Tutorial Practice and Reference Reference

Common React Error Messages and How to Fix Them

Lesson 153 of 156 5 min read By Deepak Paswan Updated Oct 10, 2026

Concept lesson · explains an idea. Code is shown for reading, not run.

This is a lookup table. The messages below are the exact texts printed by React 19.3 (development build) when we triggered each mistake in the course playground, plus a few from Vite and Babel. Search the page for the start of your message.

Rendering errors

MessageCauseFix
Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead.You put a plain object in JSX: {user}Render a field ({user.name}) or JSON.stringify for debugging. Rendering Dynamic Values
Each child in a list should have a unique “key” prop. (followed by “Check the render method of App.”)A map returns elements without keyAdd a stable key={item.id} to the outer element. Keys
Encountered two children with the same key, a. Keys should be unique so that components maintain their identity across updates.Two siblings share a keyUse unique ids.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.A missing export, or import { X } for a default export (or the reverse)Match export default with import X from and named exports with import { X } from. Importing and Exporting
X is not definedA component or variable was used without importing or declaring it, or a typoImport it or fix the spelling (components are case-sensitive).
Cannot read properties of undefined (reading ‘map’)undefined.map(...): the data has not arrived or has another shapeDefault to [], use ?., check loading first. Rendering API Responses
The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + ’em’}} when using JSX.style="color:red"style={{ color: "red" }}. Attributes
Invalid DOM property class. Did you mean className?HTML attribute namesUse className, htmlFor.
In HTML, <button> cannot be a descendant of <button>. This will cause a hydration error.Invalid nesting of elements (also <div> in <p>, <a> in <a>)Fix the HTML structure.

State and update loops

MessageCauseFix
Too many re-renders. React limits the number of renders to prevent an infinite loop.A setter was called during render (setN(n + 1) in the body, or onClick={setN(1)})Call setters in handlers or effects: onClick={() => setN(1)}. Common Rendering Mistakes
Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn’t have a dependency array, or one of the dependencies changes on every render.An effect sets state on every renderAdd a correct dependency array, remove objects and functions created during render from it, or calculate the value instead. Effect Dependencies
The screen does not update (no message)State was mutated (push, assignment)Set a new array or object. Avoiding Mutation

Hooks

MessageCauseFix
Invalid hook call. Hooks can only be called inside of the body of a function component.A hook was called outside a component or custom hook, in a class, or there are two copies of ReactCall hooks at the top level of components and use... functions. Rules of Hooks
Rendered more hooks than during the previous render. (plus “React has detected a change in the order of Hooks called by App”)A hook is called conditionally and the condition became trueMove the condition inside the hook, or into a child component.
Rendered fewer hooks than expected. This may be caused by an accidental early return statement.A hook is skipped by a condition or an early returnCall all hooks before any return.

Forms

MessageCauseFix
You provided a value prop to a form field without an onChange handler. This will render a read-only field. If the field should be mutable use defaultValue. Otherwise, set either onChange or readOnly.A controlled input without onChangeAdd onChange, or use defaultValue. Controlled Inputs
A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen.State started as undefined and later became a stringStart with useState("").

Compile-time (Babel in the playground, Vite in a project)

MessageCauseFix
Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?Two elements returned side by sideWrap them in a parent or a Fragment. Fragments
Unexpected token }. Did you mean &rbrace; or {'}'}? (for example after <div>;)An unclosed tag, so the parser reads the next characters as textClose the tag.
Unexpected reserved word ‘await’.await outside an async functionMake the function async, or use .then.
Cannot import “x” here. (this course’s playground)The playground has only react and react-domUse a full project for packages and extra files. Playground Guide

In a Vite project

MessageCauseFix
Failed to resolve import “./X” from “src/App.jsx”. Does the file exist?A wrong path, wrong letter case or missing extensionCheck the path and the exact file name.
The JSX syntax extension is not currently enabled (or an “Invalid JS syntax” error in a .js file with JSX)JSX inside a .js fileName files with JSX .jsx (or .tsx).
ReactDOM.render is not a functionOld tutorial code; removed in React 19createRoot(...).render(...). Rendering Components
Failed to fetch dynamically imported moduleA lazy chunk no longer exists after a new deployReload; add an error boundary. Production Errors
Minified React error #NNNA production build message, shortenedOpen the link in the message to read the full text.
Blocked by CORS policyThe API does not allow your site’s originFix on the server or use your own backend. API Security

How to use an error message

  1. Read the whole first message, not only the title.
  2. Find the file and line and the component stack.
  3. Search for a key phrase in this table or on react.dev.
  4. If the message is unclear, reproduce it in a small example in the playground.

See also Debugging React Applications.