Last active
April 8, 2018 10:55
-
-
Save kdichev/3d57c8c3f21751d23f10f83b86361beb 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
const asyncAction = (dataMaybe) => async (dispatch, getState) => { | |
// u can dispatch all kinds of actions here according to outcome | |
dispatch({type: "FETCHING_START"} | |
// if u need to use store data but can be passed as arg from react component when invoking | |
const store = getState().theReducer | |
const response = await myFetchFunction() | |
if (response) { | |
dispatch({type: "FETCHING_SUCCESS", payload: {response}} | |
} | |
if (error) { | |
dispatch({type: "FETCHING_ERROR"} | |
} | |
}; | |
const mapDispatchToProps = dispatch => ({ | |
handleMySexyAction: () => dispatch({type: "DO_SEXY_STUFF" }), | |
handleMyAsyncAction: (dataMaybe) => dispatch(asyncAction(dataMaybe)) | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment