Objects are not valid as a React child

Learn why React throws objects are not valid as a React child, how to fix it, and how to render objects safely in JSX.

Published

Updated

Read time 3 min read

Reviewed byDeepak Prasad

Objects are not valid as a React child

The React error "Objects are not valid as a React child" appears when JSX tries to render a plain object as a child. React can render strings, numbers, elements, arrays of renderable values, fragments, portals, and null / undefined (nothing), but not a generic { ... } object.

The fix is always one of: render a primitive from the object, map the object into elements, use JSON.stringify only for debugging, or serialize with a dedicated UI (tables, definition lists). If the data comes from an API, JSON.stringify pretty print can help you inspect the payload in DevTools before you decide what to render.

Where this runs: The snippets below are JSX — use a React project (Vite, Next.js, CRA) or paste into a .jsx / .tsx file. The small console.log examples run in Node.js and mirror the values you would show in JSX.


Method 1: Render a property instead of the whole object

Passing the whole object triggers the error; pass a string or number field instead.

jsx
function UserName() {
  const user = { name: "Ana", role: "admin" };
  // Invalid — do not render the object itself:
  // return <div>{user}</div>;

  return <div>{user.name}</div>;
}

Equivalent values in plain JavaScript (what React will eventually display):

javascript
const user = { name: "Ana", role: "admin" };
console.log("react-child-name:", user.name);
Output

You should see one line logging react-child-name: Ana.


Method 2: Render a list from object entries

When you need several fields, map Object.entries to elements and give each row a stable key (here the property name).

jsx
function UserDetails() {
  const user = { name: "Ana", role: "admin" };
  return (
    <ul>
      {Object.entries(user).map(([key, value]) => (
        <li key={key}>
          <strong>{key}:</strong> {String(value)}
        </li>
      ))}
    </ul>
  );
}

Same data shaping without JSX:

javascript
const user = { name: "Ana", role: "admin" };
console.log(
  "react-child-entries:",
  Object.entries(user)
    .map(([key, value]) => `${key}:${value}`)
    .join(" | ")
);
Output

You should see one line logging react-child-entries: name:Ana | role:admin.


Method 3: JSON.stringify for debugging only

JSON.stringify() is fine in logs or temporary UI while you build the real renderer. Do not ship large JSON.stringify blobs as the final user-facing design.

javascript
const user = { name: "Ana", role: "admin" };
console.log("react-child-json:", JSON.stringify(user));
Output

You should see one line logging react-child-json: {"name":"Ana","role":"admin"}.

In JSX you could write {JSON.stringify(user)} during development, but prefer structured markup from Method 1 or 2 for production.


Summary

The error means JSX received a plain object where it expected renderable children. Fix it by rendering fields, mapping entries to elements with keys, or stringifying only for debugging. Arrays are allowed if every element is itself renderable — an array of objects is still wrong unless you map each object to JSX.


Official documentation

Steve Alila

Specializes in web design, WordPress development, and data analysis, with proficiency in Python, JavaScript, and data extraction tools. Additionally, he excels in web API development, AI integration, …