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;
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.