Skip to content

Commit 070c7c0

Browse files
committed
fix: throw error when initial state is undefined
1 parent d00e08f commit 070c7c0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/toolkit/src/createSlice.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ export function createSlice<
262262
if (!name) {
263263
throw new Error('`name` is a required option for createSlice')
264264
}
265+
266+
if (
267+
typeof process !== 'undefined' &&
268+
process.env.NODE_ENV === 'development'
269+
) {
270+
if(options.initialState === undefined) {
271+
throw new Error('initial state must be different of undefined')
272+
}
273+
}
274+
265275
const initialState =
266276
typeof options.initialState == 'function'
267277
? options.initialState

0 commit comments

Comments
 (0)