I create weather application and use API openweathermap. I fetch data from API, but network in console show infinity request.
My React code:
class CityWeather extends Component {
constructor(props){
super(props)
this.state = {
city: "",
temp: "",
date: "Today"
}
}
render() {
const fetchWeatherData = location => {
const url = 'http://api.openweathermap.org/data/2.5/forecast?q='+location+'&units=metric&APPID=65ea63d33ba78059603a85cba8c80620';
fetch(url).then(res =>
res.json()
).then(data => {
this.setState({
city: data.city.name,
temp: data.list[0].main.temp
})
})
}
return (
<div>
{fetchWeatherData(this.props.name)}
<div>{this.state.city}</div>
<div>{this.state.date}</div>
<div>{this.state.temp}</div>
</div>
)
}
}