I am setting up a React app with a Rails backend. I am getting the error \"Objects are not valid as a React child (found: object with keys {id, name, info, created_at, updat
Just to add to the other options, I was trying to access a nested object within the main object through the dot method as in:
this.state.arrayData.CompleteAdress.Location
In this case Location is a nested object inside Complete address which is why i cant simply access it with the dot notation.
I hope it will help someone else.
This error seems to occur also when you UNintentionally send an object to React child components.
Example of it is passing to child component new Date('....') as follows:
const data = {name: 'ABC', startDate: new Date('2011-11-11')}
...
<GenInfo params={data}/>
If you send it as value of a child component parameter you would be sending a complex Object and you may get the same error as stated above.
Check if you are passing something similar (that generates Object under the hood).
In your state, home is initialized as an array
homes: []
In your return, there is an attempt to render home (which is an array).
<p>Stuff: {homes}</p>
Cannot be done this way --- If you want to render it, you need to render an array into each single item. For example: using map()
Ex: {home.map(item=>item)}
Your data homes
is an array, so you would have to iterate over the array using Array.prototype.map() for it to work.
return (
<div className="col">
<h1>Mi Casa</h1>
<p>This is my house y'all!</p>
{homes.map(home => <div>{home.name}</div>)}
</div>
);
Although not specific to the answer, this error mostly occurs when you mistakenly using a JavaScript expression inside a JavaScript context using {}
For example
let x=5;
export default function App(){ return( {x} ); };
Correct way to do this would be
let x=5;
export default function App(){ return( x ); };