Objects are not valid as a React child
React JavaScript Library
Severity: MinorWhat it means
React: Objects are not valid as a React child (found: object with keys {id, name}). If you meant to render a collection of children, use an array instead.
The part in parentheses shows what was passed: the object's keys, or a type such as [object Date].
In a production build only the number shows: Minified React error #31.
Affected Models
- React 16.8 and later
How to Fix It
-
Show a field, not the whole object: {user.name}, not {user}. The keys in the message tell you which fields there are.
-
A Date? Turn it into text first: {date.toLocaleDateString()}.
-
A list of objects? Map it to elements: {users.map(u => <li key={u.id}>{u.name}</li>)}.
-
Just want to look at it while debugging? Render it as text: <pre>{JSON.stringify(data, null, 2)}</pre>.