Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 React array.map返回预期的赋值或函数调用,而不是看到表达式_Javascript_Arrays_Reactjs_Javascript Objects_Array Map - Fatal编程技术网

Javascript React array.map返回预期的赋值或函数调用,而不是看到表达式

Javascript React array.map返回预期的赋值或函数调用,而不是看到表达式,javascript,arrays,reactjs,javascript-objects,array-map,Javascript,Arrays,Reactjs,Javascript Objects,Array Map,我编写了一个非常简单的react组件,其中我尝试从jsonplaceholder/typicode网站获取一个API。我能够成功获得结果并将其设置为状态。现在,当我尝试使用array.map在屏幕上打印这些结果时,我得到以下错误 Expected an assignment or function call and instead saw an expression no-unused-expressions 这是组件的外观: class App extends Component {

我编写了一个非常简单的react组件,其中我尝试从jsonplaceholder/typicode网站获取一个API。我能够成功获得结果并将其设置为状态。现在,当我尝试使用array.map在屏幕上打印这些结果时,我得到以下错误

Expected an assignment or function call and instead saw an expression  no-unused-expressions
这是组件的外观:

class App extends Component {
  constructor(props) {
    super(props);
    this.state = { 
      result: []
     }
  }

  componentDidMount() {
    fetch("https://jsonplaceholder.typicode.com/posts")
    .then(res=> res.json())
    .then(result=>{
      this.setState({
        result
      })
    })
  }
  
  render() { 
    return ( 
      <div>
        {this.state.result.map(post=>{
          <h1>{post.title}</h1>
        })}
      </div>
     );
  }
}
类应用程序扩展组件{
建造师(道具){
超级(道具);
this.state={
结果:[]
}
}
componentDidMount(){
取回(“https://jsonplaceholder.typicode.com/posts")
.then(res=>res.json())
。然后(结果=>{
这是我的国家({
结果
})
})
}
render(){
报税表(
{this.state.result.map(post=>{
{post.title}
})}
);
}
}

我不明白我做错了什么。有人请看一下

您忘了
返回

<div>
  {this.state.result.map((post) => {
    return <h1>{post.title}</h1>
  })}
</div>


{this.state.result.map((post)=>{
返回{post.title}
})}
用于演示的代码沙盒


您忘了返回

<div>
  {this.state.result.map((post) => {
    return <h1>{post.title}</h1>
  })}
</div>


{this.state.result.map((post)=>{
返回{post.title}
})}
用于演示的代码沙盒


非常感谢您。有时候你确实需要一双眼睛来发现一个愚蠢的错误。再次感谢,非常感谢。有时候你确实需要一双眼睛来发现一个愚蠢的错误。不过,再次谢谢你。