Javascript 应在reactjs上的箭头函数末尾返回一个值。如何修复此错误? const items=this.state.events .filter((数据)=>{ if(this.state.search==null)返回数据; 否则如果( ... ... ) { 返回数据; } }) .map((数据)=>{ 返回( {data.title} {data.description} ); });
这是我的函数,我尝试了不同的返回方式,但仍然得到错误,希望返回箭头函数末尾的值。Javascript 应在reactjs上的箭头函数末尾返回一个值。如何修复此错误? const items=this.state.events .filter((数据)=>{ if(this.state.search==null)返回数据; 否则如果( ... ... ) { 返回数据; } }) .map((数据)=>{ 返回( {data.title} {data.description} ); });,javascript,reactjs,Javascript,Reactjs,这是我的函数,我尝试了不同的返回方式,但仍然得到错误,希望返回箭头函数末尾的值。 有人能帮我解决这个问题吗?对于逻辑的每个分支,都应该有一个有效的返回值 const items = this.state.events .filter((data) => { if (this.state.search == null) return data; else if ( ... ... ) { return data;
有人能帮我解决这个问题吗?对于逻辑的每个分支,都应该有一个有效的返回值
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>
);
});
.filter((数据)=>{
if(this.state.search==null){
return data;//听起来像是一个linter警告,而不是JavaScript本身会产生的反应。您使用的是eslint吗?
.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;
})