Last active
February 21, 2019 23:55
-
-
Save jednano/40ec42f973448b8a88a9fda01e99bda5 to your computer and use it in GitHub Desktop.
TypeScript React Thunk Action Creator
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
import { Action } from 'redux'; | |
import { AppActionCreator } from '.'; | |
interface FooAction extends Action<'FOO'> { | |
payload: string; | |
} | |
export const foo: AppActionCreator<FooAction> = ( | |
bar: string, | |
) => (dispatch, getState) => | |
dispatch({ | |
payload: bar + getState().baz, | |
type: 'FOO', | |
}); |
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
import { Action } from 'redux'; | |
import { ThunkAction } from 'redux-thunk'; | |
import { AppState } from '../store'; | |
export type AppActionCreator< | |
A extends Action, | |
/** | |
* Result | |
*/ | |
R = A, | |
/** | |
* Extra argument in callback signature | |
*/ | |
E = void, | |
/** | |
* State returned when calling `getState` | |
*/ | |
S = AppState | |
// tslint:disable-next-line:no-any | |
> = (...args: any[]) => ThunkAction<R, S, E, A> | R; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment