The error "Objects are not valid as a React child" occurs when you try to render a plain JavaScript object directly in JSX. React can only render strings, numbers, arrays, or React elements "" not plain objects.
// Wrong Problem "" rendering an object
const user = { id: 1, name: "Alice" };
return <div>{user}</div>; // Error!
// Correct Solution "" render specific properties
return <div>{user.name}</div>;
// Correct Or use JSON.stringify for debugging
return <div>{JSON.stringify(user)}</div>;
function UserCard({ user }) {
return (
<div>
<p>{user}</p> {/* Error! user is an object */}
</div>
);
}
function UserCard({ user }) {
return (
<div>
<p>{user.name}</p> {/* Correct Access specific property */}
<p>{user.email}</p>
</div>
);
}
const createdAt = new Date();
return <p>Created: {createdAt}</p>; // Error!
const createdAt = new Date();
return <p>Created: {createdAt.toLocaleDateString()}</p>; // Correct
// Or
return <p>Created: {createdAt.toString()}</p>; // Correct
function App() {
const data = fetch('/api/data').then(r => r.json()); // Promise!
return <div>{data}</div>; // Error!
}
function App() {
const [data, setData] = useState(null);
useEffect(() => {
fetch('/api/data')
.then(r => r.json())
.then(setData); // Correct Store resolved value in state
}, []);
return <div>{data?.name}</div>;
}
const [status, setStatus] = useState({ loading: true, error: null });
return <p>{status}</p>; // Error! status is an object
const [status, setStatus] = useState({ loading: true, error: null });
return (
<div>
{status.loading && <p>Loading...</p>} {/* Correct */}
{status.error && <p>{status.error}</p>} {/* Correct */}
</div>
);
Try this next
0 of 2 completed
JSX braces accept a JavaScript expression, but React still needs the expression to become renderable output. user is a plain object, and React does not know which field you meant to display or how it should become DOM text. user.name is a string or number, so React can render it.
The map call transforms each object into something React can render, usually a JSX element with selected fields inside it. The object itself is not rendered; the returned <li>, <Card>, or text value is.
A Date instance is still an object, even though it represents a single value. React will not guess whether you want a locale date, ISO string, time-only display, or relative label.
Explore 500+ free tutorials across 20+ languages and frameworks.