![](/img/trans.png)
[英]Expected to return a value at the end of arrow function: 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.