Skip to content

Instantly share code, notes, and snippets.

@vldvel
Last active June 12, 2020 06:33
Show Gist options
  • Save vldvel/1c301c470557e84171671d02ba073ff1 to your computer and use it in GitHub Desktop.
Save vldvel/1c301c470557e84171671d02ba073ff1 to your computer and use it in GitHub Desktop.
Setting the timeout in the WeatherApp component to constantly pull weather data.
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