在 React js 中显示过滤器方法的警告
Showing warning for filter method in React js
我收到警告,因为 预期 return 箭头函数数组回调-return
末尾的值
我正在使用 axios 和 json 服务器删除选定的 post,在删除每个 post 之后,我只是 return 创建新数组
.then(() => {
const remainingPosts = this.props.posts.filter((post) => {
if (post.id !== this.state.loadedPost.id) {
return post
}
})
如果我注释掉 if 条件我不会收到警告,否则我会收到警告
您只需要在过滤器中提供真假条件
.then(() => {
const remainingPosts = this.props.posts.filter((post) => {
return post.id !== this.state.loadedPost.id
})
甚至更简单
.then(() => {
const remainingPosts = this.props.posts.filter((post) => (
post.id !== this.state.loadedPost.id
))
我收到警告,因为 预期 return 箭头函数数组回调-return
末尾的值我正在使用 axios 和 json 服务器删除选定的 post,在删除每个 post 之后,我只是 return 创建新数组
.then(() => {
const remainingPosts = this.props.posts.filter((post) => {
if (post.id !== this.state.loadedPost.id) {
return post
}
})
如果我注释掉 if 条件我不会收到警告,否则我会收到警告
您只需要在过滤器中提供真假条件
.then(() => {
const remainingPosts = this.props.posts.filter((post) => {
return post.id !== this.state.loadedPost.id
})
甚至更简单
.then(() => {
const remainingPosts = this.props.posts.filter((post) => (
post.id !== this.state.loadedPost.id
))