Skip to content

Bug: Improve clarity of “Objects are not valid as a React child” error message #34530

@mouadabdelmalki

Description

@mouadabdelmalki

When passing an object as a child, React currently shows:

Objects are not valid as a React child (found: [object Object])

For beginners, this message can be confusing. It may be more helpful if the error:

  • Suggests checking for JSON.stringify(obj) or mapping over arrays of objects.
  • Provides a link to relevant docs.

Proposal: Update the error message to something like:

"Objects cannot be rendered as children. Did you mean to convert it to a string with JSON.stringify(obj), or render its properties in JSX?"

This would make the error more beginner-friendly and reduce common confusion.

React version: 18.x (latest stable)

Steps To Reproduce

1 - Create a new React app (e.g., with create-react-app, Vite, or CodeSandbox).

2 - Add the following component:

export default function App() {
const obj = { name: "React" };
return

{obj}
;
}

3 - Run the application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions