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.
// ❌ Problem "” rendering an object
const user = { id: 1, name: "Alice" };
return <div>{user}</div>; // Error!
// ✅ Solution "” render specific properties
return <div>{user.name}</div>;
// ✅ 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> {/* ✅ 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>; // ✅
// Or
return <p>Created: {createdAt.toString()}</p>; // ✅
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); // ✅ 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>} {/* ✅ */}
{status.error && <p>{status.error}</p>} {/* ✅ */}
</div>
);
React's rendering engine only knows how to display strings, numbers, arrays, and React elements. Plain JavaScript objects have no defined way to be converted to DOM output, so React throws an error.
Access specific properties using dot notation (e.g., user.name), map over arrays of objects, or use JSON.stringify() for debugging purposes.
Date is a JavaScript object, not a primitive. Convert it to a string first using .toString(), .toLocaleDateString(), or .toISOString().
Use useEffect to fetch data and useState to store the resolved value. Never render the Promise itself "” wait for it to resolve and store the result in state.
Yes! null, undefined, and false are valid React children "” they render nothing. Only plain objects (non-null) cause this error.
Explore 500+ free tutorials across 20+ languages and frameworks.