2017-12-18 144 views
0

我得到预计在箭头函数数组回调返回结束返回一个值示出了用于过滤器的方法的警告在阵营JS

我正在删除使用Axios公司和JSON服务器的选择后的警告作为,删除的每篇文章之后,我马上就返回新数组

.then(() => { 
     const remainingPosts = this.props.posts.filter((post) => { 
      if (post.id !== this.state.loadedPost.id) { 
      return post 
      } 
     }) 

如果我注释掉if条件我没有得到警告,否则我得到的警告

+0

它的eslint警告[该文档是在这里(https://eslint.org/docs/rules/array-callback-返回) – wgcrouch

+0

谢谢wgcrouch,如果条件我给予只是返回false它为我工作感谢链接 –

回答

3

你只需要提供一个TR在过滤

.then(() => { 
    const remainingPosts = this.props.posts.filter((post) => { 
     return post.id !== this.state.loadedPost.id 

    }) 

或者更简单的假条件UE

.then(() => { 
    const remainingPosts = this.props.posts.filter((post) => (
     post.id !== this.state.loadedPost.id 
    )) 
+0

我试过上面的代码也适用于我!感谢您的回应 –