I am new to React and javascript as whole. I want to receive data from the server and render it on the front-end. the data I get is in array form, so I loop through the data to save it to an array and then loop back through the array to render the elements in un-ordered list. when I console.log() the data, it shows what I receive but when I console.log() the length of array it shows 0 and doesn't add what I receive. if any clue please, please respond. any help would be really appreciated.thanks
constructor(){
super();
this.notes = [];
}
componentDidMount() {
axios.get('http://localhost:4000/getnotes')
.then(response =>{
response.data.forEach((note)=>{
console.log(note.title),
this.notes.push(note) // something isn't quite right here
}
)
});
console.log(this.notes.length);
}
render(){
return(
<div>
<ul><li>default li</li>
{
this.notes.map((note)=>{
return(
<li>
{note.title}
</li>
);
})
}
</ul>
</div>
);
}