I am new to react and I am trying to create a foreach loop. However when its outputted in the browser it shows like this
[object Object][object Object][object Object]
Not sure why its happening
Below is my code any help would be really appreciated. Thanks!
const Book =({book_info})=> {
let output = "";
book_info.forEach(book => {
//console.log(book.title);
output += <h1> {book.title}</h1>
});
console.log(output);
return <section>
{output}
</section>
};
const Library = () => {
let book_info = [{title:"The sun also rises", author:"Ernest Hemigway",pages: 260},{title:"The sun also rises", author:"Ernest Hemigway",pages: 260},{title:"The sun also rises", author:"Ernest Hemigway",pages: 260}];
return (
<div>
<Book book_info={book_info}/>
</div>
)
};