Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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
Reactjs &引用;“没有未使用的表达”;使用映射函数进行反应时出错_Reactjs_Components_Es6 Map - Fatal编程技术网

Reactjs &引用;“没有未使用的表达”;使用映射函数进行反应时出错

Reactjs &引用;“没有未使用的表达”;使用映射函数进行反应时出错,reactjs,components,es6-map,Reactjs,Components,Es6 Map,我创建了一个“App”类,并在子“Todos”组件中作为道具传递了一个状态 看看我的代码: class App extends Component { state = { todos:[ { id:1, title:'task1', complete:false, },{ id:2, title:'task2', complete:false, },{ id:3, t

我创建了一个“App”类,并在子“Todos”组件中作为道具传递了一个状态

看看我的代码:

class App extends Component {

  state = {
  todos:[
    {
      id:1,
      title:'task1',
      complete:false,
    },{
      id:2,
      title:'task2',
      complete:false,
    },{
      id:3,
      title:'task3',
      complete:false,
    }
  ]
}

render() {
  return (
    <div className="App">
      <Todos todos={this.state.todos}/>
    </div>
  );
 }
}
现在,在map函数中的Todos组件中,它不允许我使用大括号,但如果我用圆括号替换它,这很好,为什么


请帮帮我。很抱歉这个结构不好的问题。

如果您使用大括号,这意味着您正在编写一个函数,最后应该返回一些
jsx
,但您的代码没有返回任何
jsx
。 所以有效的代码应该是

return this.props.todos.map((list)=>{ return list.title});
带圆括号的代码之所以有效,是因为它是编写返回的简写。 所以基本上用圆括号,你的代码仍然是这样的

return this.props.todos.map((list)=>{ return list.title});
一些有效的方法:

return this.props.todos.map((list)=>{ return list.title});

return this.props.todos.map((list)=> list.title);

除非使用显式的
返回值,否则它不会返回带花括号的任何内容。警告是什么?它是否告诉您映射函数返回未定义的
return this.props.todos.map((list)=>{ return list.title});

return this.props.todos.map((list)=> list.title);