我的代码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>
)
}
}
如何重构该代码以消除警告?
答案 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>
)
}
}
基本上,该规则表示所有代码路径必须显式返回一些值。