It is necessary to get values ??from an array of objects and display them on the screen. Now I get an error in the console: Error: Objects are not valid as a React child (found: object with keys {title}). If you meant to render a collection of children, use an array instead.
It also says in the console: The above error occurred in the component. How can this problem be solved?
ListItem.js:
const ListItem = (props) => {
return (
<div>
<h2>{props}</h2>
</div>
);
};
export default ListItem;
List.js:
import ListItem from "./ListItem/ListItem";
const listObj = [
{
title: "House 1",
},
{
title: "House 2",
},
{
title: "House 3",
},
];
function HouseList() {
return listObj.map((house, index) => {
return <ListItem key={index} title={house.title} />;
});
}
const List = () => {
return (
<div style={{ width: "50%" }}>
<HouseList />
</div>
);
};
export default List;