componentDidMount() { xhr = new XMLHttpRequest(); xhr.open("GET", "https://ipinfo.io/json", true); xhr.send(); // why not after the addEventListener? xhr.addEventListener("readystatechange", this.processRequest, false); } processRequest() { if (xhr.readyState === 4 && xhr.status === 200) { var response = JSON.parse(xhr.responseText); this.setState({ ip_address: response.ip }); } }