Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 应在reactjs上的箭头函数末尾返回一个值。如何修复此错误? const items=this.state.events .filter((数据)=>{ if(this.state.search==null)返回数据; 否则如果( ... ... ) { 返回数据; } }) .map((数据)=>{ 返回( {data.title} {data.description} ); });_Javascript_Reactjs - Fatal编程技术网

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; 
})