【发布时间】:2020-02-17 04:50:04
【问题描述】:
我是 Reactjs 的初学者。我正在尝试使用 fetch 从 jasonplaceholder api 获取 cmets 并显示它们。 我收到以下错误:- 预期分配或函数调用,而是看到一个表达式
Code
import React, { Component } from 'react'
export default class Comments extends Component {
constructor() {
super()
this.state = {
comments: []
}
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/comments')
.then(response => response.json())
.then(comments => {
this.setState({ comments: comments })
});
}
render() {
console.log(this.state.comments, "comments")
return (
<div className="conatiner">
<p>All Comments :-</p>
{
this.state.comments.map((comment) => {
<ul key={comment.id}>
<li>{comment.email}</li>
<li>{comment.body}</li>
</ul>
})
}
</div>
)
}
}
【问题讨论】:
-
错字:在地图内添加
return。
标签: reactjs