簡體   English   中英

預期在箭頭函數array-callback-return的末尾返回一個值

[英]Expected to return a value at the end of arrow function array-callback-return

我的代碼中有eslint警告Expected to return a value at the end of arrow function array-callback-return

這是代碼

return (
      <div className={cx('houseMap')}>
        {templateProperties.template.map(({ component, field, children }, idx) => {
          if (properties[field.toLowerCase()]) {
            return this.buildComponent(idx, component, field, children)
          }
        })}
      </div>
    )
  }
}

如何重構該代碼以擺脫警告?

您具有不返回值的代碼路徑。 您需要提供某種回報:

 return ( <div className={cx('houseMap')}> {templateProperties.template.map(({ component, field, children }, idx) => { if (properties[field.toLowerCase()]) { return this.buildComponent(idx, component, field, children) } return "SOMETHING in case if arg is true" })} </div> ) } } 

基本上,此規則表示所有代碼路徑必須顯式返回一些值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM