问题描述
我编写了一个非常简单的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>
);
}
}
我不明白我在做什么错。有人请看