Last active
June 12, 2020 06:33
-
-
Save vldvel/1c301c470557e84171671d02ba073ff1 to your computer and use it in GitHub Desktop.
Setting the timeout in the WeatherApp component to constantly pull weather data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeatherApp extends React.Component { | |
updateTimeout; | |
componentDidMount() { | |
this.getWeatherData(); | |
} | |
getWeatherData = async () => { | |
await this.props.getWeatherData(); | |
this.updateTimeout = setTimeout(this.getWeatherData, 30 * 1000); | |
} | |
componentWillUnmount() { | |
clearTimeout(updateTimeout); | |
} | |
render() { | |
return ( | |
<div> | |
{this.props.weatherData} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment