Skip to content

Commit fbfe514

Browse files
change reducer type validation place (#4452)
Co-authored-by: Tim Dorr <git@timdorr.com>
1 parent a075431 commit fbfe514

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/createStore.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export default function createStore<
6868
preloadedState?: PreloadedState<S> | StoreEnhancer<Ext, StateExt>,
6969
enhancer?: StoreEnhancer<Ext, StateExt>
7070
): Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext {
71+
if (typeof reducer !== 'function') {
72+
throw new Error(
73+
`Expected the root reducer to be a function. Instead, received: '${kindOf(
74+
reducer
75+
)}'`
76+
)
77+
}
78+
7179
if (
7280
(typeof preloadedState === 'function' && typeof enhancer === 'function') ||
7381
(typeof enhancer === 'function' && typeof arguments[3] === 'function')
@@ -99,14 +107,6 @@ export default function createStore<
99107
) as Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext
100108
}
101109

102-
if (typeof reducer !== 'function') {
103-
throw new Error(
104-
`Expected the root reducer to be a function. Instead, received: '${kindOf(
105-
reducer
106-
)}'`
107-
)
108-
}
109-
110110
let currentReducer = reducer
111111
let currentState = preloadedState as S
112112
let currentListeners: (() => void)[] | null = []

0 commit comments

Comments
 (0)