const api_key ='09e33ec3a8beb8e071a993a59de37c17';
class WeatherApp extends React.Component{
constructor(props){
super(props);
this.state = {
city: 'Dhaka',
description: ''
}
}
componentDidMount(){
this.grabWeather(this.state.city);
}
grabWeather(city){
fetch(`http://api.openweathermap.org/data/2.5/weather?APPID=${api_key}&q=${city}`)
.then(response => response.json())
.then(json => {
this.setState({description: json.weather[0].description})
});
console.log("working");
}
render(){
return(
<div>
<h1>Today's Weather</h1>
<h2>City: { this.state.city }</h2>
<h2>Description: {this.state.description}</h2>
</div>
);
}
}
ReactDOM.render(<WeatherApp />,
document.getElementById("app"));
I have added Babel as the pre-processor and added React and ReactDOM from the quick-add. I can see the output when I put it in jsbin but not in codepen. Can anybody tell me what is wrong with it?
Here is the link.