Skip to content

Commit 8b5d210

Browse files
committed
Make parameter of createDispatchWithMiddlewareHookFactory nullable
1 parent dff4cd2 commit 8b5d210

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

packages/toolkit/src/dynamicMiddleware/react/index.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ interface ReactDynamicMiddlewareInstance<
5454
Dispatch extends ReduxDispatch<UnknownAction> = ReduxDispatch<UnknownAction>,
5555
> extends DynamicMiddlewareInstance<State, Dispatch> {
5656
createDispatchWithMiddlewareHookFactory: (
57-
context?: Context<
58-
ReactReduxContextValue<State, ActionFromDispatch<Dispatch>>
59-
>,
57+
context?: Context<ReactReduxContextValue<
58+
State,
59+
ActionFromDispatch<Dispatch>
60+
> | null>,
6061
) => CreateDispatchWithMiddlewareHook<State, Dispatch>
6162
createDispatchWithMiddlewareHook: CreateDispatchWithMiddlewareHook<
6263
State,
@@ -71,20 +72,15 @@ export const createDynamicMiddleware = <
7172
const instance = cDM<State, Dispatch>()
7273
const createDispatchWithMiddlewareHookFactory = (
7374
// @ts-ignore
74-
context: Context<
75-
ReactReduxContextValue<State, ActionFromDispatch<Dispatch>>
76-
> = ReactReduxContext,
75+
context: Context<ReactReduxContextValue<
76+
State,
77+
ActionFromDispatch<Dispatch>
78+
> | null> = ReactReduxContext,
7779
) => {
7880
const useDispatch =
79-
// @ts-ignore
8081
context === ReactReduxContext
8182
? useDefaultDispatch
82-
: createDispatchHook(
83-
context as Context<ReactReduxContextValue<
84-
State,
85-
ActionFromDispatch<Dispatch>
86-
> | null>,
87-
)
83+
: createDispatchHook(context)
8884
function createDispatchWithMiddlewareHook<
8985
Middlewares extends Middleware<any, State, Dispatch>[],
9086
>(...middlewares: Middlewares) {

packages/toolkit/src/dynamicMiddleware/tests/react.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const typedInstance = createDynamicMiddleware<number, AppDispatch>()
1515
declare const compatibleMiddleware: Middleware<{}, number, AppDispatch>
1616
declare const incompatibleMiddleware: Middleware<{}, string, AppDispatch>
1717

18-
declare const customContext: Context<ReactReduxContextValue>
18+
declare const customContext: Context<ReactReduxContextValue | null>
1919

2020
declare const addedMiddleware: Middleware<(n: 2) => 2>
2121

packages/toolkit/src/dynamicMiddleware/tests/react.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('createReactDynamicMiddleware', () => {
7171
gDM().prepend(dynamicInstance.middleware).concat(staticMiddleware),
7272
})
7373

74-
const context = React.createContext<ReactReduxContextValue>(null as any)
74+
const context = React.createContext<ReactReduxContextValue | null>(null)
7575

7676
const createDispatchWithMiddlewareHook =
7777
dynamicInstance.createDispatchWithMiddlewareHookFactory(context)

0 commit comments

Comments
 (0)