diff --git a/src/store/index.ts b/src/store/index.ts index 8ffe3c0..6730d53 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -5,6 +5,8 @@ import { createStore, applyMiddleware } from "redux"; import { persistStore } from "redux-persist"; import thunkMiddleware from "redux-thunk"; import { createLogger } from "redux-logger"; +import { ActionMeta } from "redux-actions"; +import { useDispatch } from "react-redux"; import promiseMiddleware from "./promise-middleware"; @@ -23,6 +25,13 @@ if (process.env.NODE_ENV === "development") { middleware.push(createLogger()); } +export function useAsyncDispatch() { + const dispatch = useDispatch(); + return function asyncDispatch(action: ActionMeta, V>): Promise> { + return dispatch(action) as any; + }; +} + export const store = createStore( reducers, applyMiddleware(...middleware)