预期在箭头函数array-callback-return

时间:2018-12-25 12:41:58

标签: javascript 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>
    )
  }
}

如何重构该代码以消除警告?

1 个答案:

答案 0 :(得分:1)

您具有不返回值的代码路径。您需要提供某种回报:

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>
    )
  }
}

基本上,该规则表示所有代码路径必须显式返回一些值。

相关问题