Trying to return weatherMsg which is a string created from a request to weather API. It is correctly requesting the weather as shown by console log.
What is return is the initial value of '' instead.
class Weather extends React.Component {
render() {
let request = require('request');
let apiKey = process.env.REACT_APP_WEATHER_API_KEY;
let city = process.env.REACT_APP_WEATHER_CITY;
let url = `http://api.openweathermap.org/data/2.5/weather?id=${city}&units=imperial&appid=${apiKey}`
let weatherMsg = '';
request(url, function (err, response, body) {
if(err){
console.log('error retrieving weather');
} else {
let weather = JSON.parse(body);
console.log(weather);
weatherMsg = "It's {this.state.weather.main.temp} degrees in {this.state.weather.name}.";
}
});
return(
<div>{weatherMsg}</div>
)
}
}