Skip to content

Instantly share code, notes, and snippets.

@vldvel
Created June 12, 2020 06:34
Show Gist options
  • Save vldvel/42f3ff63224643d39c3ad915b12d9d97 to your computer and use it in GitHub Desktop.
Save vldvel/42f3ff63224643d39c3ad915b12d9d97 to your computer and use it in GitHub Desktop.
Creating inital actions in the WeatherApp component to constantly pull weather data.
export const initActions = async dispatch => {
let updateTimeout;
getWeatherDataTimedout = async () => {
await dispatch(getWeatherData());
updateTimeout = setTimeout(getWeatherDataTimedout, 30 * 1000);
}
/** Initialize any other actions */
getWeatherDataTimedout();
}
class WeatherApp extends React.Component {
componentDidMount() {
this.props.initActions();
}
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