2017-12-18 189 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

我試過上面的代碼也適用於我!感謝您的迴應 –