Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Objects are not valid as a React child: what React accepts

React renders primitives, null and elements, not plain objects. Find the object leaking into JSX, then render a field or serialize it deliberately.

~4 min readReact
#React#JSX#Rendering#Debugging
A React render tree with an object crate jammed into a child slot, a cyan serializer gate beside it

Introduction & Quick Summary

text
Uncaught Error: Objects are not valid as a React child (found: object with keys {id, name, createdAt}). If you meant to render a collection of children, use an array instead.

React renders strings, numbers, null, undefined, booleans, arrays of those, and React elements. Anything else that has a $$typeof of its own is fine; a plain object is not. When JSX places an object between tags or passes one as children, React throws at render time with the keys of the offending object, which is usually enough to identify the field.

The six shapes that cause it:

  • A whole API object in JSX. {user} instead of {user.name}.
  • A Date, Map, Set or class instance. All objects, none renderable.
  • A promise handed to a component. In React 19 an unawaited promise surfaces as this error inside the boundary that tries to render it.
  • An array of objects. Arrays are allowed, but their elements are checked, so items.map((i) => i) fails on the first item.
  • children typed loosely. A component that spreads {...props} into a DOM node passes the object straight through.
  • A ternary returning an object. {isOpen && dialogConfig} looks conditional but ships an object when true.
ExpressionRenders?Error text
{user.name}Yesn/a
{user}Nofound: object with keys {...}
{new Date()}Nofound: object with keys {}
{[1, 2, 3]}Yesn/a
{[{ a: 1 }]}NoSame, pointing at the element
{Promise.resolve(1)}No, React 19A component suspended or object error
{() => 1}NoFunctions are not valid as a React child

Core Mechanics, Signatures & Reproducible Setup

React.Children and the reconciler classify children before rendering. Strings, numbers and bigints become text nodes, null/undefined/booleans render as nothing, arrays and iterables are flattened, and elements are matched by $$typeof (react.element, react.transitional.element in React 19). A plain object fails every branch and throws with describeObjectForErrorMessage, which lists up to a handful of own keys.

Reproduce it with a single component:

jsx
const user = { id: 1, name: "Ada", createdAt: new Date() }; function Profile() { return <p>{user}</p>; } // Uncaught Error: Objects are not valid as a React child (found: object with keys {id, name, createdAt})

The fix is to select a primitive at the boundary:

jsx
function Profile() { return ( <p> {user.id} {user.name} {user.createdAt.toISOString()} </p> ); }

A serializer helper keeps deep objects from leaking into JSX at all:

tsx
function asText(value: unknown): string { if (value === null || value === undefined) return ""; if (typeof value === "string" || typeof value === "number") return String(value); if (value instanceof Date) return value.toISOString(); if (Array.isArray(value)) return value.map(asText).join(", "); if (typeof value === "object") return JSON.stringify(value); return String(value); } // <span>{asText(payload.detail)}</span>

That helper is also the pragmatic answer when the payload shape is unknown at the edge of the app and only needs to be visible for debugging.

Key Comparison Table

Value typeReact child?Correct render path
string, numberYesDirect
booleanYes, renders nothingUse for conditionals
null, undefinedYes, renders nothingGuard clauses
DateNotoISOString() or Intl.DateTimeFormat
Map, SetNoConvert with Array.from
Plain objectNoDestructure or serialize
Array of primitivesYesMap to strings
Array of elementsYesmap with key
SituationWhy it happensPractical fix
{data} from useQueryThe whole query result is an objectRender data.title
{error} from a catchError instances are objectsRender error.message
{children} passed as configA config object reaches JSXFlatten before render
Object inside <option><option>{obj}</option>Use obj.label
Object in a template literalSilent [object Object], no throwSame fix, worse symptom

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

Case 1: An object spread into a DOM element

tsx
function Badge(props: { children: React.ReactNode; tone?: object }) { return <span {...props} />; }

{...props} places tone on a DOM node, and React serializes unknown props as attributes, which fails once the value is an object. Destructure the props you intend to forward:

tsx
function Badge({ children, tone, ...rest }: BadgeProps) { return <span data-tone={String(tone)} {...rest}>{children}</span>; }

Case 2: A conditional that returns a config object

tsx
{isOpen && { title: "Confirm", body: "Sure?" }}

This is a valid boolean-AND in JavaScript and an invalid child in React. Use a ternary with null on the false branch and render fields explicitly.

Case 3: Map rendered directly

tsx
const totals = new Map([["eu", 10], ["us", 20]]); return <ul>{totals}</ul>; // objects are not valid as a React child
tsx
return ( <ul> {[...totals].map(([region, amount]) => ( <li key={region}>{region}: {amount}</li> ))} </ul> );

Case 4: An unawaited promise from an async function

tsx
async function loadName() { return "Ada"; } function Name() { const name = loadName(); // Promise return <span>{name}</span>; }

React 19 can surface this as the object error rather than a suspension warning when the promise has already settled, which makes it trickier to spot. Await it in the caller or use use() inside a component that is wrapped in Suspense.

Case 5: useId-style objects in a list

tsx
const rows = [{ key: { id: 1 }, label: "A" }]; return rows.map((r) => <li key={r.key}>{r.label}</li>);

The key prop is special and does accept objects for identity purposes, but rendering r.key elsewhere throws. Keep a stable primitive identifier for both.

Case 6: Server data through a form action

tsx
const [state, formAction] = useActionState(save, { error: null, fields: {} }); return <form action={formAction}><p>{state}</p></form>;

Render state.error and iterate state.fields, not the state object itself. The same pattern catches people migrating from useFormState.

Common Compilation/Runtime Mistakes & Version Gotchas

  • React 19 error identity changed. The thrown object is now a plain Error with a structured message; error boundaries that matched on message text need updating.
  • React.Children.toArray is not a serializer. It flattens and keys children but keeps objects as objects, so it will not rescue a bad payload.
  • String(obj) in JSX passes silently. {"Name: " + obj} renders Name: [object Object] with no throw, which is worse than the error because it reaches production. Prefer explicit field access.
  • Fragments mask the location. <>{obj}</> reports the fragment's parent, not the exact expression, so search the component for object-typed props when the stack is unhelpful.
  • Server Components. Passing an object as children from a server component to a client component is allowed and serialized, but rendering it there throws the same way. The rule is about rendering, not passing.
  • TypeScript does not catch it. ReactNode excludes plain objects, so typed code usually fails at compile time, meaning most occurrences come from any, index signatures, or untyped JS.

For payloads that arrive as JSON from an API, prettify them in the JSON formatter to see the actual shape before writing JSX, and compare a failing response with a known-good one using the diff tool. If the object comes from a YAML config rendered into a docs page, the YAML viewer catches type mistakes such as a date being parsed as an object.

Primary references: React's rendering rules for children and the isValidElement check describe exactly what the reconciler accepts.

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.