-
Notifications
You must be signed in to change notification settings - Fork 49.4k
Open
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug
Description
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
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug