I have a programm in React that
does a http-request during componentWillMount and sets a variable response on the response of the http-request
var response = "";
class App extends Component{
componentWillMount(){
var myRequest = new XMLHttpRequest(),
method = 'GET',
url = //url;
myRequest.open(method, url, true);
myRequest.send();
myRequest.onload = function() {
response = myRequest.response;
};
and that displays the response in the method render() by using the "response" variable.
However, this is not working -> the initial value "" is displayed. The HTTP-Request is working (tested), the HTTP-Response is recieved and correct(also tested), so perhaps the program is just not waiting untill the http request is done and instead takes the initial value for "response".
How can i fix this, i.e. how can i enforce that response is set to the HTTP-response?