Hello guys,
Please i need help.
when I click on the delete button, on the first react exercise, all the categories are deleted instead only one.
That’s most probably because at the time Mosh recorded the tutorial the Javascript version for the Filter method didn’t require a return for the method, but now the best thing to do is:
handleDelete = (movie) => {
const movies = this.state.movies.filter((mov) => {
return mov._id !== movie._id;
});
this.setState({ movies: movies });
};
Thanks Kodertian! It works.
Hi @Kodertian.
It isn’t due to differences in JavaScript versions. The actual reason is that when you put curly braces ({}
) around the body, you need to explicitly write the return
keyword, or otherwise it means that you aren’t returning anything.
Developer.mozilla explains it well (see Step 2.):
// Traditional Function
function (a){
return a + 100;
}
// Arrow Function Break Down
// 1. Remove the word "function" and place arrow between the argument and opening body bracket
(a) => {
return a + 100;
}
// 2. Remove the body brackets and word "return" -- the return is implied.
(a) => a + 100;
// 3. Remove the argument parentheses
a => a + 100;
@Andreson26 I hope you understand the issue now.
1 Like
Thanks man for the tip!