@@ -15,55 +15,65 @@ import isPlainObject from './utils/isPlainObject'
15
15
import { kindOf } from './utils/kindOf'
16
16
17
17
/**
18
- * Creates a Redux store that holds the state tree.
19
- * The only way to change the data in the store is to call `dispatch()` on it.
18
+ * @deprecated
20
19
*
21
- * There should only be a single store in your app. To specify how different
22
- * parts of the state tree respond to actions, you may combine several reducers
23
- * into a single reducer function by using `combineReducers`.
20
+ * **We recommend using the `configureStore` method
21
+ * of the `@reduxjs/toolkit` package**, which replaces `createStore`.
24
22
*
25
- * @param reducer A function that returns the next state tree, given
26
- * the current state tree and the action to handle .
23
+ * Redux Toolkit is our recommended approach for writing Redux logic today,
24
+ * including store setup, reducers, data fetching, and more .
27
25
*
28
- * @param preloadedState The initial state. You may optionally specify it
29
- * to hydrate the state from the server in universal apps, or to restore a
30
- * previously serialized user session.
31
- * If you use `combineReducers` to produce the root reducer function, this must be
32
- * an object with the same shape as `combineReducers` keys.
26
+ * **For more details, please read this Redux docs page:**
27
+ * **https://redux.js.org/introduction/why-rtk-is-redux-today**
33
28
*
34
- * @param enhancer The store enhancer. You may optionally specify it
35
- * to enhance the store with third-party capabilities such as middleware,
36
- * time travel, persistence, etc. The only store enhancer that ships with Redux
37
- * is `applyMiddleware()`.
29
+ * `configureStore` from Redux Toolkit is an improved version of `createStore` that
30
+ * simplifies setup and helps avoid common bugs.
31
+ *
32
+ * You should not be using the `redux` core package by itself today, except for learning purposes.
33
+ * The `createStore` method from the core `redux` package will not be removed, but we encourage
34
+ * all users to migrate to using Redux Toolkit for all Redux code.
35
+ *
36
+ * If you want to use `createStore` without this visual deprecation warning, use
37
+ * the `legacy_createStore` import instead:
38
+ *
39
+ * `import { legacy_createStore as createStore} from 'redux'`
38
40
*
39
- * @returns A Redux store that lets you read the state, dispatch actions
40
- * and subscribe to changes.
41
41
*/
42
- export default function createStore <
43
- S ,
44
- A extends Action ,
45
- Ext = { } ,
46
- StateExt = never
47
- > (
42
+ export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
48
43
reducer : Reducer < S , A > ,
49
44
enhancer ?: StoreEnhancer < Ext , StateExt >
50
45
) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
51
- export default function createStore <
52
- S ,
53
- A extends Action ,
54
- Ext = { } ,
55
- StateExt = never
56
- > (
46
+ /**
47
+ * @deprecated
48
+ *
49
+ * **We recommend using the `configureStore` method
50
+ * of the `@reduxjs/toolkit` package**, which replaces `createStore`.
51
+ *
52
+ * Redux Toolkit is our recommended approach for writing Redux logic today,
53
+ * including store setup, reducers, data fetching, and more.
54
+ *
55
+ * **For more details, please read this Redux docs page:**
56
+ * **https://redux.js.org/introduction/why-rtk-is-redux-today**
57
+ *
58
+ * `configureStore` from Redux Toolkit is an improved version of `createStore` that
59
+ * simplifies setup and helps avoid common bugs.
60
+ *
61
+ * You should not be using the `redux` core package by itself today, except for learning purposes.
62
+ * The `createStore` method from the core `redux` package will not be removed, but we encourage
63
+ * all users to migrate to using Redux Toolkit for all Redux code.
64
+ *
65
+ * If you want to use `createStore` without this visual deprecation warning, use
66
+ * the `legacy_createStore` import instead:
67
+ *
68
+ * `import { legacy_createStore as createStore} from 'redux'`
69
+ *
70
+ */
71
+ export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
57
72
reducer : Reducer < S , A > ,
58
73
preloadedState ?: PreloadedState < S > ,
59
74
enhancer ?: StoreEnhancer < Ext , StateExt >
60
75
) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
61
- export default function createStore <
62
- S ,
63
- A extends Action ,
64
- Ext = { } ,
65
- StateExt = never
66
- > (
76
+ export function createStore < S , A extends Action , Ext = { } , StateExt = never > (
67
77
reducer : Reducer < S , A > ,
68
78
preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
69
79
enhancer ?: StoreEnhancer < Ext , StateExt >
@@ -367,3 +377,95 @@ export default function createStore<
367
377
} as unknown as Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
368
378
return store
369
379
}
380
+
381
+ /**
382
+ * Creates a Redux store that holds the state tree.
383
+ *
384
+ * **We recommend using `configureStore` from the
385
+ * `@reduxjs/toolkit` package**, which replaces `createStore`:
386
+ * **https://redux.js.org/introduction/why-rtk-is-redux-today**
387
+ *
388
+ * The only way to change the data in the store is to call `dispatch()` on it.
389
+ *
390
+ * There should only be a single store in your app. To specify how different
391
+ * parts of the state tree respond to actions, you may combine several reducers
392
+ * into a single reducer function by using `combineReducers`.
393
+ *
394
+ * @param {Function } reducer A function that returns the next state tree, given
395
+ * the current state tree and the action to handle.
396
+ *
397
+ * @param {any } [preloadedState] The initial state. You may optionally specify it
398
+ * to hydrate the state from the server in universal apps, or to restore a
399
+ * previously serialized user session.
400
+ * If you use `combineReducers` to produce the root reducer function, this must be
401
+ * an object with the same shape as `combineReducers` keys.
402
+ *
403
+ * @param {Function } [enhancer] The store enhancer. You may optionally specify it
404
+ * to enhance the store with third-party capabilities such as middleware,
405
+ * time travel, persistence, etc. The only store enhancer that ships with Redux
406
+ * is `applyMiddleware()`.
407
+ *
408
+ * @returns {Store } A Redux store that lets you read the state, dispatch actions
409
+ * and subscribe to changes.
410
+ */
411
+ export function legacy_createStore <
412
+ S ,
413
+ A extends Action ,
414
+ Ext = { } ,
415
+ StateExt = never
416
+ > (
417
+ reducer : Reducer < S , A > ,
418
+ enhancer ?: StoreEnhancer < Ext , StateExt >
419
+ ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
420
+ /**
421
+ * Creates a Redux store that holds the state tree.
422
+ *
423
+ * **We recommend using `configureStore` from the
424
+ * `@reduxjs/toolkit` package**, which replaces `createStore`:
425
+ * **https://redux.js.org/introduction/why-rtk-is-redux-today**
426
+ *
427
+ * The only way to change the data in the store is to call `dispatch()` on it.
428
+ *
429
+ * There should only be a single store in your app. To specify how different
430
+ * parts of the state tree respond to actions, you may combine several reducers
431
+ * into a single reducer function by using `combineReducers`.
432
+ *
433
+ * @param {Function } reducer A function that returns the next state tree, given
434
+ * the current state tree and the action to handle.
435
+ *
436
+ * @param {any } [preloadedState] The initial state. You may optionally specify it
437
+ * to hydrate the state from the server in universal apps, or to restore a
438
+ * previously serialized user session.
439
+ * If you use `combineReducers` to produce the root reducer function, this must be
440
+ * an object with the same shape as `combineReducers` keys.
441
+ *
442
+ * @param {Function } [enhancer] The store enhancer. You may optionally specify it
443
+ * to enhance the store with third-party capabilities such as middleware,
444
+ * time travel, persistence, etc. The only store enhancer that ships with Redux
445
+ * is `applyMiddleware()`.
446
+ *
447
+ * @returns {Store } A Redux store that lets you read the state, dispatch actions
448
+ * and subscribe to changes.
449
+ */
450
+ export function legacy_createStore <
451
+ S ,
452
+ A extends Action ,
453
+ Ext = { } ,
454
+ StateExt = never
455
+ > (
456
+ reducer : Reducer < S , A > ,
457
+ preloadedState ?: PreloadedState < S > ,
458
+ enhancer ?: StoreEnhancer < Ext , StateExt >
459
+ ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext
460
+ export function legacy_createStore <
461
+ S ,
462
+ A extends Action ,
463
+ Ext = { } ,
464
+ StateExt = never
465
+ > (
466
+ reducer : Reducer < S , A > ,
467
+ preloadedState ?: PreloadedState < S > | StoreEnhancer < Ext , StateExt > ,
468
+ enhancer ?: StoreEnhancer < Ext , StateExt >
469
+ ) : Store < ExtendState < S , StateExt > , A , StateExt , Ext > & Ext {
470
+ return createStore ( reducer , preloadedState as any , enhancer )
471
+ }
0 commit comments