Why did I get this error(after npm run build)? While handleDelete is defined.
BlogList.js:
const BlogList = ({blogs, title, handleDelete}) => {
return(
<div className="blog-list">
<h2>{title}</h2>
{blogs.map((blog) => (
<div className="blog-preview" key={blog.id}>
<h2>{blog.title}</h2>
<p>Written by {blog.author}</p>
<button onClick={() => handleDelete(blog.id)}>
Delete Blog
</button>
</div>
))}
</div>
)
}
export default BlogList;
Home.js
import BlogList from "./BlogList";
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 }
]);
const handleDelete = (id) => {
const newBlogs = blogs.filter(blog => blog.id !== id);
setBlogs(newBlogs);
}
return(
<div className="Home">
<BlogList blogs={blogs} title="All Blogs" handleDelete={handleDelete} />
</div>
);
}
export default Home;