Skip to content

Instantly share code, notes, and snippets.

@vahidvdn
Created January 6, 2022 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vahidvdn/74f4d4503c6af0489359aef4b68c2ebf to your computer and use it in GitHub Desktop.
Save vahidvdn/74f4d4503c6af0489359aef4b68c2ebf to your computer and use it in GitHub Desktop.
// with thunk, instead of returning an object, we can return a function (for async tasks)
const callHttp = () => {
return function (dispatch) {
dispatch(beforeCall())
axios.get()
.then((res) => {
dispatch(afterSuccess(res.data))
})
.catch((error) => {
dispatch(afterFail(error.message))
})
}
}
const mapDispatchToProps = (dispatch) => {
return {
deletePost: (id) => dispatch(callHttp())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment