【发布时间】:2020-09-11 06:00:14
【问题描述】:
我想知道为什么我的 React 类的格式是错误的?它说应该有一个括号,但我确实包括了一个括号?不过,我可能会忘记语法格式的某些方面:( 这是我的 js 文件中的一个 sn-p:
function App() {
state = {
posts = [];
input = '';
};
componentDidMount = () => {
this.getPosts();
};
getPosts = () => {
axios.get('(server)')
// replace (server) with server link
.then((response) => {
const data = response.data;
this.setState({ posts: data });
})
}
displayBlogPost = (posts) => {
if (!posts.length) return null;
return posts.map((post, index) => (
<div key={index} className="post__display">
<h3>"name " + post.name </h3>
<h3>"City " + post.location </h3>
<h3>"Requesting " + post.type </h3>
<h3> post.message </h3>
</div>
));
};
render() {
return (
<div className="App">
<header>
<h2> Covunity </h2>
<SearchExample items= { this.state.posts } />
</header>
</div>
<div className="gallery">
{this.displayBlogPost(this.state.posts)} </div>
)
document.getElementById('root')
}
}
错误信息是
Syntax error: Unexpected token, expected ";" (54:12)
(在渲染()处)
【问题讨论】:
标签: reactjs error-handling syntax frontend