Skip to content
Tutorials Center
My learning

Topics

React Reference ยท Concepts and Pitfalls

Common React warnings

What the most common React development warnings mean and how to fix them: missing keys, unknown props, DOM nesting, controlled inputs, act and setState in render.

React's development build prints warnings through console.error when it detects code that works today but is likely to break, or is already wrong. They never appear in production builds, so a clean console in development matters. Most warnings come from a short list of mistakes. This page explains the ones you will meet most often, what React is telling you, and the fix.

Warnings are written as messages with placeholders that the console fills in (the component name and prop name). The examples below show the main wording; exact text varies slightly between versions, so search for the distinctive phrase.

JSX
// Each child in a list should have a unique "key" prop.
items.map((item) => <li>{item.name}</li>)

Try it

Trigger several warnings on purpose
The corrected versions

The second example should leave the console clean.

The warnings, one by one

"Each child in a list should have a unique key prop"

Elements created in an array need a key that is stable and unique among siblings, so React can tell which item is which when the list changes. Use a database id or other stable identifier, not the array index for lists that can be reordered or filtered, and never a random value. Fragments in a list need the key too (<Fragment key={id}>). See key.

"React does not recognize the x prop on a DOM element" and "Invalid DOM property"

DOM elements accept standard attribute names written the React way: className, htmlFor, tabIndex, onClick (camelCase events). Custom data uses data-* and ARIA uses aria-*; both stay hyphenated. This warning often means a prop meant for your own component was spread onto a DOM element (<div {...props}>). Pick the props the element needs instead of spreading everything.

"In HTML, <div> cannot be a descendant of <p>" (DOM nesting)

The browser's HTML parser rewrites invalid structures on the server, so the DOM no longer matches what React expects and hydration fails. Typical offenders: block elements inside <p>, <a> inside <a>, <tr> without <tbody>, <li> outside a list. Fix the structure.

"You provided a value prop to a form field without an onChange handler"

A field with value is controlled, so React expects you to update the value. Add onChange, add readOnly if it is deliberately fixed, or use defaultValue for an uncontrolled field. See value and defaultValue.

"A component is changing an uncontrolled input to be controlled"

The value went from undefined or null to a real string (or back). Initialize state with '' and keep it a string. Missing data should become an empty string, not undefined.

"Cannot update a component while rendering a different component"

A child called a parent's setState during its render. Rendering must be pure. Move the update to an event handler, or to an effect if it must follow rendering. Calling the component's own setter during render to adjust state from props is allowed but rare (see Derived state).

"An update to X inside a test was not wrapped in act(...)"

In tests, a state update happened outside act, so React cannot be sure the UI settled before your assertion. Wrap interactions and awaited work in act (imported from react), or use Testing Library's helpers, which do it for you. See act.

"Maximum update depth exceeded"

A state update runs on every render (setState in the render body, or in an effect without a correct dependency array), producing an endless loop. See Infinite render loops.

"Rendered more hooks than during the previous render"

Hooks were called conditionally, in loops, or after an early return. Hooks must run in the same order every render; see Rules of Hooks.

Hydration warnings

"Hydration failed because the server rendered HTML didn't match the client" means the first client render differs from the server HTML. See Hydration.

Usage notes

  • Read the component stack. Each warning names the component where the problem occurs; start there.
  • React 19 prints no Warning: prefix, so search by the message itself.
  • Fix warnings; do not silence them. They are cheaper to fix now than as production bugs. suppressHydrationWarning is only for one-off text differences.
  • Strict Mode adds warnings about impure rendering, unsafe effects and legacy APIs. It runs only in development.
  • Removed warnings: the old "can't perform a state update on an unmounted component" warning is gone, and "Function components cannot be given refs" no longer applies because ref is a normal prop for function components in React 19.
  • ESLint with eslint-plugin-react-hooks catches many of these before you run the code (see ESLint plugin).