Last active
February 5, 2019 05:13
-
-
Save carlrip/054620b1ad1ae6c6c0dad0e5ce71c652 to your computer and use it in GitHub Desktop.
React Redux Action Creators with TypeScript - example 2
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 postPersonActionCreator: ActionCreator< | |
ThunkAction< | |
Promise<IPostedPersonAction>, // The type of the last action to be dispatched - will always be promise<T> for async actions | |
IPostPersonResult, // The type for the data within the last action | |
IPostPerson, // The type of the parameter for the nested function | |
IPostedPersonAction // The type of the last action to be dispatched | |
> | |
> = (person: IPostPerson) => { | |
return async (dispatch: Dispatch) => { | |
const postingPersonAction: IPostingPersonAction = { | |
type: 'PostingPerson', | |
}; | |
dispatch(postingPersonAction); | |
const result = await postPersonFromApi(person); | |
const postPersonAction: IPostedPersonAction = { | |
type: 'PostedPerson', | |
result, | |
}; | |
return dispatch(postPersonAction); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment