I have the following Axios request:
componentDidMount() {
axios.post('http://localhost:3030/api/weather/refresh').then(response => {
store.dispatch(refreshWeather(response))
});
}
This sends a dispatch to Redux which is used to feed the presentational container in the common pattern.
My question is - how can I make it do this axios.post() request is re-usable in other components or parts of the app? I have got as far as having it in an external file which is imported, but is there a better way to structure my project so all axios requests are grouped together?
I have the following mapDispatchToProps:
const mapDispatchToProps = (dispatch, ownProps) => {
return {
onClickRefresh: () => {
dispatch(refreshWeather(arr))
}
}
}
And I want to run the same request as the componentDidMount(), but not sure of the best way to make re-usable as explained above.
Thanks