React throws 'Objects are not valid as a React child'
Objects are not valid as a React child (found: object with keys {id, name})Short answer
React can render elements, strings, numbers, empty values and arrays of those. A plain object, or an array of plain objects, is none of these, so JSX that places one between braces fails. Find the value named in the message, then render its fields, map it to elements, or read a Promise with use().
Fix it fast
1Find out which cause you have
Read the keys the message prints. They identify the object. Then log the value that you put in braces.
console.log(typeof value, Array.isArray(value), value);2Match what you see, then jump to its fix
- 1
The message lists the object's keys, for example {street, city}A whole object (often a nested one) is put in JSXFix - 2
The value is an array whose items are objectsAn array of objects is placed in JSX without mappingFix - 3
The value comes from fetch() or an async functionA Promise is rendered instead of its resultFix
- 1
What does the error look like?
Objects are not valid as a React child (found: object with keys {id, name})If you meant to render a collection of children, use an array instead.
Cause 1 of 3
A whole object (often a nested one) is put in JSX
1Check
React accepts elements, strings, numbers, portals, null, undefined, booleans and arrays of nodes as children. An object is not on that list.
grep -rn "{user\.\|{data}" src/ | head2Fix
Render the fields you want, one by one.
// Fails
<p>{user.address}</p>
// Works
<p>{user.address.street}, {user.address.city}</p>3Verify
The page renders and the message is gone.
# reload the pageConfirmed by react.dev
Cause 2 of 3
An array of objects is placed in JSX without mapping
1Check
An array is fine only when its items are valid React nodes. Objects first have to be turned into elements.
console.log(Array.isArray(items), items[0]);2Fix
Map each object to an element with a unique key.
<ul>
{items.map(item => (
<li key={item.id}>{item.name}</li>
))}
</ul>3Verify
One list item appears for each object.
# reload the pageConfirmed by react.dev
Cause 3 of 3
A Promise is rendered instead of its result
1Check
A Promise is an object. Rendering it directly fails, and an async function used as a component returns one.
console.log(value instanceof Promise);2Fix
Read the Promise with use() under a Suspense boundary. The Promise must be created outside render, for example in a Server Component or a cache, so the same instance is reused.
import { use, Suspense } from 'react';
function Albums({ albumsPromise }) {
const albums = use(albumsPromise);
return <ul>{albums.map(a => <li key={a.id}>{a.title}</li>)}</ul>;
}
<Suspense fallback={<h2>Loading...</h2>}>
<Albums albumsPromise={albumsPromise} />
</Suspense>3Verify
The fallback shows while loading and the list replaces it.
# reload the pageConfirmed by react.dev
How do I stop it coming back?
- Type API responses so a field that is an object cannot be placed in JSX by accident.
- Use JSON.stringify(value) only for debugging output, never as the final UI.
- Keep data fetching out of render, and pass Promises down from where they are created.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
React was asked to render something that is not a component (it 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.
React received something that is not a tag name or a component, most often undefined, because the import resolved to nothing.
4 causes, each with a fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb apps
TypeScript rejects MUI Data Grid columns that set a type
A TypeScript error inside a column's renderCell callback
A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.
2 causes, each with a fix