[英]React array.map returns Expected an assignment or function call and instead saw an expression
I have written a very simple react component where-in I try to fetch an API from the jsonplaceholder/typicode website.我编写了一个非常简单的反应组件,其中我尝试从 jsonplaceholder/typicode 网站获取 API。 I am able to successfully get the result and set it in state.
我能够成功获得结果并将其设置为状态。 Now, when I try to print those result on the screen using array.map, I get the following error
现在,当我尝试使用 array.map 在屏幕上打印这些结果时,出现以下错误
Expected an assignment or function call and instead saw an expression no-unused-expressions
This is how the component looks like:这是组件的样子:
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>
);
}
}
I don't understand what am I doing wrong here.我不明白我在这里做错了什么。 Someone please have a look
有人请看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.