store: add a useAsyncDispatch function for type-correct async dispatch.
parent
a7cae3203b
commit
2f8794e8fd
src/store
|
@ -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<T, V>(action: ActionMeta<Promise<T>, V>): Promise<ActionMeta<T, V>> {
|
||||
return dispatch(action) as any;
|
||||
};
|
||||
}
|
||||
|
||||
export const store = createStore(
|
||||
reducers,
|
||||
applyMiddleware(...middleware)
|
||||
|
|
Loading…
Reference in New Issue