Skip to content

Commit fdf5956

Browse files
committed
Mark createStore as deprecated and add legacy_createStore
- Updated `createStore`'s doc description to mark it as `@deprecated`, so that it shows up with a visual strikethrough in editors. - Added new descriptive text to `createStore` to encourage users to migrate to RTK, and pointing to the "RTK is Redux Today" docs page - Rewrote TS typedefs for `createStore` to define it as a function with overloads, rather than a varible, to get correct docs tooltips when hovering over variable usages - Added `legacy_createStore` API as an alias without the deprecation
1 parent 051aca0 commit fdf5956

File tree

3 files changed

+170
-37
lines changed

3 files changed

+170
-37
lines changed

index.d.ts

+117-17
Original file line numberDiff line numberDiff line change
@@ -371,35 +371,135 @@ export interface StoreCreator {
371371
): Store<S & StateExt, A> & Ext
372372
}
373373

374+
/**
375+
* @deprecated
376+
*
377+
* **We recommend using the `configureStore` method
378+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
379+
*
380+
* Redux Toolkit is our recommended approach for writing Redux logic today,
381+
* including store setup, reducers, data fetching, and more.
382+
*
383+
* **For more details, please read this Redux docs page:**
384+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
385+
*
386+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
387+
* simplifies setup and helps avoid common bugs.
388+
*
389+
* You should not be using the `redux` core package by itself today, except for learning purposes.
390+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
391+
* all users to migrate to using Redux Toolkit for all Redux code.
392+
*
393+
* If you want to use `createStore` without this visual deprecation warning, use
394+
* the `legacy_createStore` import instead:
395+
*
396+
* `import { legacy_createStore as createStore} from 'redux'`
397+
*
398+
*/
399+
export declare function createStore<S, A extends Action, Ext, StateExt>(
400+
reducer: Reducer<S, A>,
401+
enhancer?: StoreEnhancer<Ext, StateExt>
402+
): Store<S & StateExt, A> & Ext
403+
/**
404+
* @deprecated
405+
*
406+
* **We recommend using the `configureStore` method
407+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
408+
*
409+
* Redux Toolkit is our recommended approach for writing Redux logic today,
410+
* including store setup, reducers, data fetching, and more.
411+
*
412+
* **For more details, please read this Redux docs page:**
413+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
414+
*
415+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
416+
* simplifies setup and helps avoid common bugs.
417+
*
418+
* You should not be using the `redux` core package by itself today, except for learning purposes.
419+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
420+
* all users to migrate to using Redux Toolkit for all Redux code.
421+
*
422+
* If you want to use `createStore` without this visual deprecation warning, use
423+
* the `legacy_createStore` import instead:
424+
*
425+
* `import { legacy_createStore as createStore} from 'redux'`
426+
*
427+
*/
428+
export declare function createStore<S, A extends Action, Ext, StateExt>(
429+
reducer: Reducer<S, A>,
430+
preloadedState?: PreloadedState<S>,
431+
enhancer?: StoreEnhancer<Ext>
432+
): Store<S & StateExt, A> & Ext
433+
374434
/**
375435
* Creates a Redux store that holds the state tree.
436+
*
437+
* **We recommend using `configureStore` from the
438+
* `@reduxjs/toolkit` package**, which replaces `createStore`:
439+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
440+
*
376441
* The only way to change the data in the store is to call `dispatch()` on it.
377442
*
378443
* There should only be a single store in your app. To specify how different
379-
* parts of the state tree respond to actions, you may combine several
380-
* reducers
444+
* parts of the state tree respond to actions, you may combine several reducers
381445
* into a single reducer function by using `combineReducers`.
382446
*
383-
* @template S State object type.
447+
* @param {Function} reducer A function that returns the next state tree, given
448+
* the current state tree and the action to handle.
384449
*
385-
* @param reducer A function that returns the next state tree, given the
386-
* current state tree and the action to handle.
450+
* @param {any} [preloadedState] The initial state. You may optionally specify it
451+
* to hydrate the state from the server in universal apps, or to restore a
452+
* previously serialized user session.
453+
* If you use `combineReducers` to produce the root reducer function, this must be
454+
* an object with the same shape as `combineReducers` keys.
387455
*
388-
* @param [preloadedState] The initial state. You may optionally specify it to
389-
* hydrate the state from the server in universal apps, or to restore a
390-
* previously serialized user session. If you use `combineReducers` to
391-
* produce the root reducer function, this must be an object with the same
392-
* shape as `combineReducers` keys.
456+
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
457+
* to enhance the store with third-party capabilities such as middleware,
458+
* time travel, persistence, etc. The only store enhancer that ships with Redux
459+
* is `applyMiddleware()`.
460+
*
461+
* @returns {Store} A Redux store that lets you read the state, dispatch actions
462+
* and subscribe to changes.
463+
*/
464+
export declare function legacy_createStore<S, A extends Action, Ext, StateExt>(
465+
reducer: Reducer<S, A>,
466+
enhancer?: StoreEnhancer<Ext, StateExt>
467+
): Store<S & StateExt, A> & Ext
468+
/**
469+
* Creates a Redux store that holds the state tree.
393470
*
394-
* @param [enhancer] The store enhancer. You may optionally specify it to
395-
* enhance the store with third-party capabilities such as middleware, time
396-
* travel, persistence, etc. The only store enhancer that ships with Redux
397-
* is `applyMiddleware()`.
471+
* **We recommend using `configureStore` from the
472+
* `@reduxjs/toolkit` package**, which replaces `createStore`:
473+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
398474
*
399-
* @returns A Redux store that lets you read the state, dispatch actions and
400-
* subscribe to changes.
475+
* The only way to change the data in the store is to call `dispatch()` on it.
476+
*
477+
* There should only be a single store in your app. To specify how different
478+
* parts of the state tree respond to actions, you may combine several reducers
479+
* into a single reducer function by using `combineReducers`.
480+
*
481+
* @param {Function} reducer A function that returns the next state tree, given
482+
* the current state tree and the action to handle.
483+
*
484+
* @param {any} [preloadedState] The initial state. You may optionally specify it
485+
* to hydrate the state from the server in universal apps, or to restore a
486+
* previously serialized user session.
487+
* If you use `combineReducers` to produce the root reducer function, this must be
488+
* an object with the same shape as `combineReducers` keys.
489+
*
490+
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
491+
* to enhance the store with third-party capabilities such as middleware,
492+
* time travel, persistence, etc. The only store enhancer that ships with Redux
493+
* is `applyMiddleware()`.
494+
*
495+
* @returns {Store} A Redux store that lets you read the state, dispatch actions
496+
* and subscribe to changes.
401497
*/
402-
export const createStore: StoreCreator
498+
export declare function legacy_createStore<S, A extends Action, Ext, StateExt>(
499+
reducer: Reducer<S, A>,
500+
preloadedState?: PreloadedState<S>,
501+
enhancer?: StoreEnhancer<Ext>
502+
): Store<S & StateExt, A> & Ext
403503

404504
/**
405505
* A store enhancer is a higher-order function that composes a store creator

src/createStore.js

+51-19
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ import isPlainObject from './utils/isPlainObject'
55
import { kindOf } from './utils/kindOf'
66

77
/**
8-
* Creates a Redux store that holds the state tree.
9-
* The only way to change the data in the store is to call `dispatch()` on it.
8+
* @deprecated
109
*
11-
* There should only be a single store in your app. To specify how different
12-
* parts of the state tree respond to actions, you may combine several reducers
13-
* into a single reducer function by using `combineReducers`.
10+
* **We recommend using the `configureStore` method
11+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
1412
*
15-
* @param {Function} reducer A function that returns the next state tree, given
16-
* the current state tree and the action to handle.
13+
* Redux Toolkit is our recommended approach for writing Redux logic today,
14+
* including store setup, reducers, data fetching, and more.
1715
*
18-
* @param {any} [preloadedState] The initial state. You may optionally specify it
19-
* to hydrate the state from the server in universal apps, or to restore a
20-
* previously serialized user session.
21-
* If you use `combineReducers` to produce the root reducer function, this must be
22-
* an object with the same shape as `combineReducers` keys.
16+
* **For more details, please read this Redux docs page:**
17+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
2318
*
24-
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
25-
* to enhance the store with third-party capabilities such as middleware,
26-
* time travel, persistence, etc. The only store enhancer that ships with Redux
27-
* is `applyMiddleware()`.
19+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
20+
* simplifies setup and helps avoid common bugs.
21+
*
22+
* You should not be using the `redux` core package by itself today, except for learning purposes.
23+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
24+
* all users to migrate to using Redux Toolkit for all Redux code.
25+
*
26+
* If you want to use `createStore` without this visual deprecation warning, use
27+
* the `legacy_createStore` import instead:
28+
*
29+
* `import { legacy_createStore as createStore} from 'redux'`
2830
*
29-
* @returns {Store} A Redux store that lets you read the state, dispatch actions
30-
* and subscribe to changes.
3131
*/
32-
export default function createStore(reducer, preloadedState, enhancer) {
32+
export function createStore(reducer, preloadedState, enhancer) {
3333
if (
3434
(typeof preloadedState === 'function' && typeof enhancer === 'function') ||
3535
(typeof enhancer === 'function' && typeof arguments[3] === 'function')
@@ -313,3 +313,35 @@ export default function createStore(reducer, preloadedState, enhancer) {
313313
[$$observable]: observable,
314314
}
315315
}
316+
317+
/**
318+
* Creates a Redux store that holds the state tree.
319+
*
320+
* **We recommend using `configureStore` from the
321+
* `@reduxjs/toolkit` package**, which replaces `createStore`:
322+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
323+
*
324+
* The only way to change the data in the store is to call `dispatch()` on it.
325+
*
326+
* There should only be a single store in your app. To specify how different
327+
* parts of the state tree respond to actions, you may combine several reducers
328+
* into a single reducer function by using `combineReducers`.
329+
*
330+
* @param {Function} reducer A function that returns the next state tree, given
331+
* the current state tree and the action to handle.
332+
*
333+
* @param {any} [preloadedState] The initial state. You may optionally specify it
334+
* to hydrate the state from the server in universal apps, or to restore a
335+
* previously serialized user session.
336+
* If you use `combineReducers` to produce the root reducer function, this must be
337+
* an object with the same shape as `combineReducers` keys.
338+
*
339+
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
340+
* to enhance the store with third-party capabilities such as middleware,
341+
* time travel, persistence, etc. The only store enhancer that ships with Redux
342+
* is `applyMiddleware()`.
343+
*
344+
* @returns {Store} A Redux store that lets you read the state, dispatch actions
345+
* and subscribe to changes.
346+
*/
347+
export const legacy_createStore = createStore

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import createStore from './createStore'
1+
import { createStore, legacy_createStore } from './createStore'
22
import combineReducers from './combineReducers'
33
import bindActionCreators from './bindActionCreators'
44
import applyMiddleware from './applyMiddleware'
@@ -28,6 +28,7 @@ if (
2828

2929
export {
3030
createStore,
31+
legacy_createStore,
3132
combineReducers,
3233
bindActionCreators,
3334
applyMiddleware,

0 commit comments

Comments
 (0)