Skip to content

Commit 0cdf85e

Browse files
Add redux-form type to AppDispatch
1 parent b65262f commit 0cdf85e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

services/common/src/redux/rootState.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { sharedReducer } from "@mds/common/redux/reducers/rootReducerShared";
2-
import { configureStore } from "@reduxjs/toolkit";
2+
import { configureStore, Dispatch } from "@reduxjs/toolkit";
33
import { loadingBarReducer } from "react-redux-loading-bar";
44

55
import type { TypedUseSelectorHook } from 'react-redux'
66
import { useDispatch, useSelector, useStore } from 'react-redux'
7+
import type { FormAction } from 'redux-form';
78

89
export const getStore = (preloadedState = {}) =>
910
configureStore({
@@ -17,10 +18,14 @@ export const getStore = (preloadedState = {}) =>
1718

1819
export const store = getStore();
1920

20-
// Provide typed versions for global redux functions
21+
/**
22+
* Provide typed versions for global redux functions
23+
**/
24+
2125
type RootState = ReturnType<typeof store.getState>;
2226

23-
export type AppDispatch = typeof store.dispatch;
27+
// Infer the `RootState` and `AppDispatch` types from the store itself + make sure redux-form actions are captured as well.
28+
export type AppDispatch = typeof store.dispatch & Dispatch<FormAction>;
2429
export type AppStore = typeof store;
2530

2631
// Use throughout your app instead of plain `useDispatch` and `useSelector`

0 commit comments

Comments
 (0)