You can only return 1 element, in your case you have 2 options, you can wrap all your elements in a single <div>
like this:
render() {
return (
<div>
<h1>Post list</h1>,
{this.state.posts_data.map(p =>
<div key={p.id}>
{p.title} , {p.id} , {p.userId}
</div>
}
</div>
);
}
or you can use <React.Fragment />
.
render() {
return (
<React.Fragment>
<h1>Post list</h1>,
{this.state.posts_data.map(p =>
<div key={p.id}>
{p.title} , {p.id} , {p.userId}
</div>
}
</React.Fragment>
);
}
Note: In React we use JSX, so if you want to use Javascript with your HTML you have to wrap it in { }
, which is why I've wrapped your this.state.posts_data.map()
in those brackets.
Make sure that this.state.posts_data
is an Array or else this will throw an error.