Hello for some reason React would not update the state globally,
componentDidMount() {
var id = window.location.href.split('/')[3]
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://reactAppBackend/edit/" + id);
xhr.send();
xhr.onloadend = () => {
this.setState({singlePost: JSON.parse(xhr.responseText)})
console.log(this.state.singlePost[0])
};
}
when I run this the console log return data this data
{_id: "5e6016adb8c32b00883f55f5", postTitle: "RE4", postContent: "the best ", __v: 0}
but when I try to render the state:
render() {
return (
<div>{this.state.singlePost[0]}</div>
)
}
it is not rendering anything.