I was wondering why my formatting is wrong for my React class? It says theres supposed to be a paranthesis but I do include a paranthesis? I might be forgetting some aspect of the syntax format, though:( This is my a snippet from my js file:
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')
}
}
and the error message is
Syntax error: Unexpected token, expected ";" (54:12)
(at render())
First, you must return a single element. Instead you return 2. Then, the last line in the render method implementation is unreachable (after the return). Try this:
render() {
return (
<div>
<div className="App">
<header>
<h2> Covunity </h2>
<SearchExample items={this.state.posts}/>
</header>
</div>
<div className="gallery">
{this.displayBlogPost(this.state.posts)}
</div>
</div>
)
// document.getElementById('root')
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.