[英]Expected to return a value at the end of arrow function on reactjs how to fix this error?
const items = this.state.events
.filter((data) => {
if (this.state.search == null) return data;
else if (
...
...
) {
return data;
}
})
.map((data) => {
return (
<div>
<span>{data.title}</span>
<span>{data.description}</span>
</div>
);
});
This is my function and i tried different ways of putting return but i still get the error Expected to return a value at the end of arrow function.这是我的函数,我尝试了不同的返回方式,但我仍然收到错误预期在箭头函数末尾返回一个值。
Can anyone help me fix this ?谁能帮我解决这个问题?
You should have a valid return for every branch of logic你应该对每个逻辑分支都有一个有效的回报
.filter((data) => {
if (this.state.search == null) {
return data; // <-- branch 1 good
} else if (...) {
return data; // <-- branch 2 good
} // implicit else
// <-- oops, branch 3 missing, add explicit return
return true;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.