我有这个代码。
{
Object.keys(_.get(order, "customer", {})).map((key) => {
if (key !== "defaultOption" && customer[key] !== "") {
return (
<option key={key} value={key}>
{_.startCase(key)}
</option>
);
}
});
}
并有以下警告
Line 885:96: Expected to return a value at the end of arrow function array-callback-return
我知道,因为我在 map
函数中使用 if
语句。那么,如何消除错误呢?
最佳答案
在
某些内容(即使它是空字符串)。if
语句之后返回
您可能希望随后从数组中过滤
此类值(或者首先过滤
数组而不是使用if
)。
关于javascript - 预期在带有 if 语句的箭头函数末尾返回一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61837472/