繁体   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