Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

React does not recognize the prop on a DOM element

React drops camelCase props it cannot map to an attribute. Destructure before spreading, prefer data-* names, and use transient props in styled-components.

~5 min readReact
#react#dom-props#styled-components#warnings
Bold white headline reading UNKNOWN PROP with a React element crate and an amber camelCase label bouncing off a cyan DOM block.

Introduction & Quick Summary

React prints a warning for a prop it will not render:

code
Warning: React does not recognize the `isActive` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `isactive` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Nothing crashes. The attribute is silently dropped, styling that depended on it looks broken, and the console fills up on every render. The cause is always the same: a prop reached a host element (<div>, <button>, <span>) with a name React does not map to a valid HTML or SVG attribute.

Quick answer: keep your own props out of the DOM node. Destructure them first, or spread only what the element accepts:

tsx
function Card({ isActive, children, ...rest }: CardProps) { return <div className={isActive ? "on" : "off"} {...rest}>{children}</div>; }

React 16 and later forward unknown attributes that are already all-lowercase, so <div customthing="x"> renders and does not warn. What it refuses is a camelCase or otherwise non-standard name, because lowercasing it could collide with a real attribute and change behaviour.

Core Mechanics, Signatures & Reproducible Setup

React keeps a list of valid DOM properties. For an attribute not on that list, the rule is:

  • If the name contains an uppercase letter, warn and do not render it.
  • If the name is lowercase and not a reserved name, render it verbatim as an attribute.
  • If the value is false, render nothing; true renders the attribute with an empty value on custom attributes but warns for non-boolean standard ones.

That is the entire mechanism, and it explains every variant of the message, including the sibling warnings Invalid DOM property 'class'. Did you mean 'className'? and Received 'true' for a non-boolean attribute.

A minimal reproduction with no libraries:

tsx
export function Badge({ count }: { count: number }) { return <span badgeCount={count}>new</span>; } // Warning: React does not recognize the `badgeCount` prop on a DOM element. export function BadgeFixed({ count }: { count: number }) { return <span data-badge-count={count}>new</span>; } // renders: <span data-badge-count="3">new</span>

The same code path catches typos in real props, which is why the warning is worth fixing rather than filtering: onclick instead of onClick, class instead of className, and tabindex instead of tabIndex all pass the component boundary and land here.

Key Comparison Table

The names people write, and what React expects:

WrittenReact expectsResult
class="btn"classNameinvalid DOM property warning, attribute dropped
for="email"htmlForinvalid DOM property warning, label breaks
onclick={fn}onClickunknown prop warning, handler never runs
tabindex="0"tabIndexunknown prop warning, focus order breaks
readonlyreadOnlyunknown prop warning on a controlled field
stroke-widthstrokeWidthvalid on SVG only; on div it is forwarded lowercase
data-id / aria-labelsameforwarded, no warning

Three warnings that look alike and are not:

WarningCauseFix
does not recognize the X propunknown camelCase prop on a host elementdestructure or rename to data-*
Invalid DOM property 'x'. Did you mean 'y'?known React name misspelleduse the React spelling
Received 'true' for a non-boolean attributeboolean passed to a string attributepass the string, or omit when false

Where the prop usually comes from:

SourceTypical shapeClean fix
component wrapper{...props} on the inner nodeconst { custom, ...rest } = props
styled-components v6$variant transient propsalready stripped when prefixed $
MUI / Chakrasx, ownerStatelibrary filters; do not forward manually
react-hook-formregister() spread plus custom propspread register fields only
custom elementcamelCase propertyset it via ref or lowercase attribute

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Destructure before the spread, and type it

tsx
type ButtonProps = React.ComponentPropsWithoutRef<"button"> & { isActive?: boolean; // not a DOM attribute }; export function Button({ isActive = false, className, ...rest }: ButtonProps) { return <button data-active={isActive} className={className} {...rest} />; }

ComponentPropsWithoutRef<"button"> gives you onClick, disabled, type, and friends with no ref conflict, and it makes any extra required prop visible at the call site instead of at the DOM boundary.

2. Transient props in styled-components v6

Version 6 made transient props strict: a $-prefixed prop is consumed by the styled component and never reaches the DOM.

tsx
const Pill = styled.span<{ $tone: "ok" | "warn" }>` color: ${(p) => (p.$tone === "ok" ? "#0a0" : "#c80")}; `; <Pill $tone="warn">degraded</Pill> // no warning, no attribute <Pill tone="warn">degraded</Pill> // warning: tone is not recognised

For emotion, the equivalent is shouldForwardProp:

tsx
const Tag = styled.div.withConfig({ shouldForwardProp: (prop) => prop !== "tone", })<{ tone: string }>`...`;

3. Filtering a whitelist when wrapping a third-party component

When you wrap a component that forwards everything, filter by the element you render:

tsx
const DOM_PROPS = new Set(["id", "className", "style", "title", "role", "onClick"]); function Surface(props: Record<string, unknown>) { const dom: Record<string, unknown> = {}; for (const [k, v] of Object.entries(props)) if (DOM_PROPS.has(k)) dom[k] = v; return <section {...dom} />; }

An allow-list ages better than a deny-list, because a new prop added to the component later cannot leak into the DOM silently.

4. Custom elements and camelCase properties

For a web component such as <my-slider>, React 19 sets properties on the element for names it finds on the instance and falls back to attributes otherwise. Passing minValue={5} to a custom element therefore works without a warning, while the same prop on a <div> warns. Do not rely on that on a host element: use a lowercase attribute, a data-* attribute, or a ref:

tsx
function Slider({ minValue }: { minValue: number }) { const ref = React.useRef<HTMLElement>(null); React.useEffect(() => { if (ref.current) ref.current.minValue = minValue; }, [minValue]); return React.createElement("my-slider", { ref }); }

viewBox, strokeWidth, fillRule, clipPath, stopColor and textAnchor are real camelCase React props and never warn. stroke-width written in JSX is forwarded lowercase and also works on an SVG element, but mixing the two styles in one file makes the warning list unreliable — pick one and stay with it.

6. Booleans and the non-boolean attribute warning

tsx
<div aria-hidden={true} /> // fine: aria-* accepts booleans <div draggable={false} /> // removed from the DOM <div tabIndex={0} /> // fine: tabIndex is numeric <a download={true} /> // warns: download is a string attribute

Use download="" or download="report.csv", and omit the attribute entirely instead of passing false where the attribute is enumerated.

Common Compilation/Runtime Mistakes & Version Gotchas

Filtering the warning instead of the prop. console.error overrides and suppressHydrationWarning do not remove an attribute; they hide the evidence. If a library is the source, patch the wrapper, not the console.

Double spread. <Card {...props} {...rest} /> where rest still contains the custom key reintroduces it, because JSX merges props left to right and the later object wins.

React 15 habits. React 15 stripped every unknown attribute silently. Code that rendered customprop="x" kept working after the upgrade to 16 but lost the attribute, and only the warning tells you. Audit wrappers written before 2018 for camelCase props that used to do nothing.

Server and client disagree. With SSR the warning can appear once on the server and again on hydration, and React 19 groups repeated warnings, so the count is not evidence of how many components are affected. Fix the first one and reload.

TypeScript does not catch it. React.HTMLAttributes<HTMLDivElement> is an interface with an index signature in older @types/react versions, so isActive type-checks even though React rejects it. ComponentPropsWithoutRef plus a strict exactOptionalPropertyTypes setup catches far more.

Checking what actually rendered. Read the DOM instead of the source when a styling bug follows this warning: the element inspector shows the attribute list, and the JSON formatter is useful when your props come from an API and you want to see which keys were forwarded. The regular expression tester helps when you grep a large repository for spread patterns such as \{\.\.\.props\} to find every wrapper that needs a destructure.

Reference material: React does not recognize the prop and Common components: DOM attributes.

Official references

primary documentation

The React documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit React work — they run entirely in this browser tab, so nothing you paste leaves your device.

All React guides

More in React

All React guides

The guides filed next to this one in React, in library order.