I need the render function of my component to be called only after the request for the componentDidMount function is completed.
componentDidMount(){
let ctx = this;
ApiService.get('/busca/empresa/pagina').then(function(response){
if(response.data.empresa){
ctx.setState({company:response.data.empresa});
ctx.getProducts();
ctx.verifyAuthentication();
}
}, function(error){
Notification.error('HTTP Status: ' + error.response.status + ' - ' + error.response.data.mensagem);
});
}
The problem is that when open page the render function is invoked before componentDidMount completed. Always returning function from else condition (renderNotValidateCompany) and returning renderValidateCompany after updating this.state.company.
render(){
if(this.state.company){
return this.renderValidateCompany();
}else{
return this.renderNotValidateCompany();
}
}
Is it possible that rendering is called only when componentDidMount is completed in react?
Thanks!
this.state={requestCompleted:false}