I want to show the blog author and blog title in the array on my html page but nothing is displayed. I used the map method and it worked but the forEach method shows nothing. I will like a solution in for loop and forEach loop Here is my code:
import { useState } from "react";
const Home = () => {
const [blogs, setBlogs] = useState([
{ title: 'My new website', body: 'lorem ipsum...', author: 'mario', id: 1 },
{ title: 'Welcome party!', body: 'lorem ipsum...', author: 'yoshi', id: 2 },
{ title: 'Web dev top tips', body: 'lorem ipsum...', author: 'mario', id: 3 }
]);
return (
<div className="home">
{blogs.forEach((blog) => {
<div className="blog-preview" key={blog.id}>
<h2>{ blog.title }</h2>
<p>Written by{ blog.author }</p>
</div>
})}
</div>
);
}export default Home;