Skip to content

Instantly share code, notes, and snippets.

@jednano
Last active February 21, 2019 23:55
Show Gist options
  • Save jednano/40ec42f973448b8a88a9fda01e99bda5 to your computer and use it in GitHub Desktop.
Save jednano/40ec42f973448b8a88a9fda01e99bda5 to your computer and use it in GitHub Desktop.
TypeScript React Thunk Action Creator
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',
});
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