I need to update the state variable from ajax response. I tried below
componentDidMount() {
var parent_object=this;
axios.get('/template.php')
.then((result)=> {
console.log(result.data);
parent_object.setState({component_template:result.data})//not updating
});
console.log("here");
console.log(this.state.component_template);
}
I can see the array for result.data
but the state variable component_template
is not updated
I tried How to set state of response from axios in react and https://daveceddia.com/ajax-requests-in-react/ but no luck