Skip to content

Error: Objects are not valid as a React child

Error message

                Objects are not valid as a React child. If you meant to render a collection of children, use an array instead.
              

Quick summary

You placed a JavaScript object directly in JSX where React expects a string, number, or React element.

Why this happens

  • Tried to render an object directly: {someObject}

  • Tried to render a Date object without calling .toString() or .toLocaleDateString()

  • Tried to render an error object directly

  • Returned an object from a component instead of JSX

Minimal example

✗ Broken code
function Profile({ user }) {
  return <div>{user}</div>; // user is an object!
}
✓ Fixed code
function Profile({ user }) {
  return <div>{user.name}</div>; // Render a specific property
}

React can't render a raw object. Accessing user.name (a string) gives React something it can render.

How to diagnose

  • Log the value being rendered to check its type

  • Look for {value} in JSX where value is an object

  • Check if the value is a Date, Error, or other object type

How to fix

  • Access a specific property: {user.name} instead of {user}

  • Convert to string: {String(value)} or {value.toString()}

  • For Dates: {date.toLocaleDateString()}

How to prevent

  • Always render primitive values (string, number) or React elements in JSX

  • Use TypeScript to catch type mismatches at compile time

Related Resources

Related Glossary

Related Lessons

  • JSX Basics

    Learn what can and cannot be rendered in JSX.

← Back to language