Created
January 6, 2022 09:29
-
-
Save vahidvdn/74f4d4503c6af0489359aef4b68c2ebf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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