I am fetching data from my API :
fetch('/api/p/' + project_id).then(res => res.json())
.then((project) => {
console.log(project)
this.setState({ project })
}
);
the project structur is like this :
{
name: "project1",
comments: ["com1", "com2"]
}
now inside my return function, I need to Loop through all comments and render them sparetly each comment on a different row so I used this code:
this.state.project.comments.map((comment) => {
return (
<p><i class="fas fa-chevron-right"></i> { comment } </p>
);
});
I am getting this Error:
TypeError: Cannot read property 'map' of undefined
I tried map or forEach and for. and also I can't get its length because I get the same error.
but if I type this.state.project.comments I get all elements in one row without space like this comment1comment2comment3