<分区>
我只是像这样在 React 的渲染函数中使用箭头函数从 API 迭代一些数据。
render() {
const postItem = this.props.posts.map((post, index) => {
<div key={post.id}>
<p>{index}</p>
<h4>{post.title}</h4>
<p>{post.body}</p>
</div>
})
return (
<div>
<p>Posts</p>
{postItem}
</div>
)
}
然后它会抛出错误
(请看箭头后面的花括号,如果把“(”放在花括号“{”的位置,那么一切都会好起来的)
比如“预期的赋值或函数调用反而看到了一个表达式”,但是如果我把 (放在 => 之后,那么一切都会好起来的。但我怀疑箭头的正确语法是这样的 () => {}。
请帮帮我。