This error occurs when attempting to render a plain JavaScript object directly in JSX. React requires you to render primitives, elements, or arrays, not raw objects.
Minified React error #31 corresponds to the full error message: "Objects are not valid as a React child (found: [object Object]). If you meant to render a collection of children, use an array instead." This error occurs when React encounters a plain JavaScript object being passed as a child element in JSX, which is not allowed. React can only render specific types of values: strings, numbers, React elements, arrays of these types, fragments, portals, and booleans (which render nothing). When you try to render an object directly, React doesn't know how to display it and throws this error. The error message is minified in production builds to reduce bundle size, but the underlying issue is always the same: attempting to render an invalid data type. This error commonly appears when developers forget to access object properties, accidentally pass entire objects instead of their values, or improperly handle API responses and state management. The error name includes a link to the React error decoder with specific arguments showing what object caused the problem.
If you're seeing the minified error, switch to development mode to get the complete error with helpful details:
# Run development build instead of production
npm run devThe full error message will show you exactly which object is causing the problem and where it's being rendered. This makes debugging much easier than working with the minified version.
Look at the component stack trace to find where you're passing an object as a child. Common patterns to look for:
// ❌ WRONG: Rendering entire object
const user = { name: "John", age: 30 };
return <div>{user}</div>;
// ❌ WRONG: Passing object in mapping
const items = [{ id: 1, name: "Item 1" }];
return <div>{items}</div>;
// ❌ WRONG: Using Date object directly
return <p>{new Date()}</p>;Check your JSX for curly braces containing variables that might be objects rather than primitives.
Replace object references with specific property access:
// ✅ CORRECT: Access individual properties
const user = { name: "John", age: 30 };
return (
<div>
<p>Name: {user.name}</p>
<p>Age: {user.age}</p>
</div>
);
// ✅ CORRECT: Convert Date to string
return <p>{new Date().toLocaleDateString()}</p>;
// ✅ CORRECT: Use JSON.stringify for debugging only
return <pre>{JSON.stringify(user, null, 2)}</pre>;Always extract renderable values (strings, numbers) from objects before passing them to JSX.
When mapping over arrays of objects, ensure you're rendering properties, not the objects themselves:
// ❌ WRONG: Returns objects
const items = [{ id: 1, name: "Item 1" }, { id: 2, name: "Item 2" }];
return <ul>{items}</ul>;
// ✅ CORRECT: Map to extract properties
return (
<ul>
{items.map(item => (
<li key={item.id}>{item.name}</li>
))}
</ul>
);
// ✅ CORRECT: Destructure in map
return (
<ul>
{items.map(({ id, name }) => (
<li key={id}>{name}</li>
))}
</ul>
);Always use proper key props when rendering lists.
If you're using Next.js 15, ensure all workspaces use React 19+:
# Check installed React versions
npm list react react-dom
# Update to React 19 if needed
npm install react@^19 react-dom@^19
# In monorepos, check all workspace package.json filesFor Next.js 15:
{
"dependencies": {
"next": "15.x",
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
}Version mismatches can cause this error even with correct JSX code.
Use TypeScript or PropTypes to catch these errors during development:
// TypeScript: Define proper prop types
interface UserDisplayProps {
name: string; // Only accept primitives
age: number;
}
function UserDisplay({ name, age }: UserDisplayProps) {
return <div>{name} is {age} years old</div>;
}
// Call with properties, not the object
const user = { name: "John", age: 30 };
<UserDisplay name={user.name} age={user.age} />// PropTypes: Runtime validation
import PropTypes from 'prop-types';
UserDisplay.propTypes = {
name: PropTypes.string.isRequired,
age: PropTypes.number.isRequired
};Type checking helps catch these errors before runtime.
Ensure API responses are properly destructured before rendering:
// ❌ WRONG: Rendering entire response object
const [data, setData] = useState(null);
return <div>{data}</div>;
// ✅ CORRECT: Extract specific fields
const [data, setData] = useState(null);
return <div>{data?.message || "Loading..."}</div>;
// ✅ CORRECT: Render array of objects properly
const [users, setUsers] = useState([]);
return (
<ul>
{users.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);Always validate and extract data from API responses before rendering.
In Next.js applications, this error can occur during server-side rendering if you're passing non-serializable objects (like Date objects or functions) as props. Use getServerSideProps or getStaticProps to serialize data properly before passing to components. For Next.js 15 specifically, the framework requires React 19+ in all workspaces within a monorepo to prevent this error, as older React versions can cause compatibility issues.
When working with complex state management libraries like Redux or Zustand, be careful not to pass entire store slices to components. Instead, use selectors to extract only the primitive values you need to render. This also improves performance by reducing unnecessary re-renders.
For debugging purposes in development, you can temporarily use JSON.stringify() to visualize object contents, but never leave this in production code as it's inefficient and creates poor user experiences. Consider using React DevTools to inspect component props and state to identify unexpected object structures.
If you're seeing this error in third-party components or UI libraries (like Forge UI Kit with Date fields, or Grafana dashboard annotations), check the library documentation for proper prop formats and consider filing bug reports if the library is passing objects incorrectly. Some libraries may have specific formatters or converters for complex data types.
React Hook useCallback has a missing dependency: 'variable'. Either include it or remove the dependency array react-hooks/exhaustive-deps
React Hook useCallback has a missing dependency
Cannot use private fields in class components without TS support
Cannot use private fields in class components without TS support
Cannot destructure property 'xxx' of 'undefined'
Cannot destructure property of undefined when accessing props
useNavigate() may be used only in the context of a <Router> component.
useNavigate() may be used only in the context of a Router component
Cannot find module or its corresponding type declarations
How to fix "Cannot find module or type declarations" in Vite