Created
June 12, 2020 06:34
-
-
Save vldvel/42f3ff63224643d39c3ad915b12d9d97 to your computer and use it in GitHub Desktop.
Creating inital actions 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
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