#create `createStore` vs `legacy_createStore` in Redux: Key Differences Explained

#create createStore vs legacy_createStore in Redux: Key Differences Explained

Both createStore and legacy_createStore create functionally identical Redux stores, but createStore displays deprecation warnings while legacy_createStore acts as a legacy alias that suppresses the visual notice, with both APIs encouraging migration to Redux Toolkit's configureStore.

The redux package has officially deprecated the traditional store creation API in favor of modern patterns provided by Redux Toolkit. Understanding the difference between createStore and legacy_createStore helps you maintain existing Redux applications while planning your migration strategy according to the reduxjs/redux source code.

What Is createStore in Redux?

createStore is the original store-creation function that has served as the primary entry point for Redux state management since the library's inception. According to the source code in src/createStore.ts (lines 51-98 and 101-506), this function handles the complete store initialization process, including argument validation, enhancer composition, internal store object creation, and dispatching the initial INIT action.

The implementation includes a prominent deprecation comment block that encourages developers to use configureStore from @reduxjs/toolkit instead. When you import createStore directly, you may encounter visual deprecation notices in your development environment, as the function is explicitly marked for removal in future major versions.

What Is legacy_createStore?

legacy_createStore is a thin wrapper function defined at lines 436-500 of src/createStore.ts that simply forwards all arguments to the main createStore implementation. The one-line function signature returns createStore(reducer, preloadedState as any, enhancer), making it functionally identical to calling createStore directly.

This alias exists specifically for legacy codebases that need to maintain the historic API surface without triggering deprecation warnings. While legacy_createStore is also technically marked as deprecated, the wrapper isolates the warning to the original createStore export, allowing teams to suppress warning noise during incremental migrations.

Key Differences Between createStore and legacy_createStore

While both functions produce identical store objects, they differ in their deprecation handling and intended use cases:

  • Deprecation Visibility: createStore displays active deprecation warnings in development tools, while legacy_createStore suppresses the visual notice despite both being marked deprecated in the source.

  • Implementation Complexity: createStore contains the full validation logic and store initialization (approximately 400 lines of implementation), whereas legacy_createStore is a single-line wrapper that delegates to the main function.

  • Migration Path: Both functions point developers toward configureStore from Redux Toolkit, but legacy_createStore provides a temporary bridge for codebases that cannot immediately migrate large portions of their store configuration.

Source Code Implementation Details

createStore Implementation

The primary implementation in src/createStore.ts (lines 101-506) contains the full store logic, including:

  • Reducer validation and enhancement composition
  • Internal state management and subscription handling
  • Dispatch method implementation with action validation
  • Observable interface for interoperability

The function signature accepts three parameters: reducer, preloadedState, and enhancer, with TypeScript overloads defined to handle various initialization patterns.

The legacy_createStore Wrapper

Located at lines 436-500 of the same file, the legacy wrapper is implemented as:

export function legacy_createStore<S, A extends Action, Ext, StateExt>(
  reducer: Reducer<S, A>,
  preloadedState?: PreloadedState<S> | StoreEnhancer<Ext, StateExt>,
  enhancer?: StoreEnhancer<Ext, StateExt>
): Store<S, A, StateExt> & Ext {
  return createStore(reducer, preloadedState as any, enhancer)
}

This wrapper maintains full type safety while delegating all runtime behavior to the deprecated createStore function.

Practical Code Examples

Using createStore (With Deprecation Warning)

import { createStore } from 'redux';
import rootReducer from './reducers';

const store = createStore(rootReducer);

This approach will display deprecation warnings in your console or IDE, signaling that you should migrate to Redux Toolkit.

Using legacy_createStore (Silenced Warning)

import { legacy_createStore as createStore } from 'redux';
import rootReducer from './reducers';

const store = createStore(rootReducer);

Functionally identical to the previous example, but the import alias avoids triggering the visual deprecation notice during the transition period.

import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './counterSlice';

export const store = configureStore({
  reducer: {
    counter: counterReducer,
  },
});

configureStore from Redux Toolkit bundles best practices including Redux DevTools integration, thunk middleware for async logic, and immutable check middleware, making it the future-proof replacement for both createStore and legacy_createStore.

Summary

  • createStore is the original, fully-implemented store creator in src/createStore.ts that now displays deprecation warnings encouraging migration to Redux Toolkit.

  • legacy_createStore is a thin wrapper in the same file that calls createStore internally but provides an alias to suppress deprecation warnings during legacy maintenance.

  • Both APIs produce identical store objects with the same method signatures and runtime behavior.

  • Redux Toolkit's configureStore is the recommended replacement, offering enhanced defaults, better TypeScript support, and built-in development tools.

Frequently Asked Questions

Is legacy_createStore deprecated?

Yes, legacy_createStore is technically deprecated according to the source code in src/createStore.ts, but it serves as a legacy escape hatch that isolates the deprecation warning from the main createStore export. This allows teams to maintain existing code without console noise while planning their migration to Redux Toolkit.

Why is createStore deprecated in Redux?

The Redux maintainers deprecated createStore to encourage adoption of Redux Toolkit, which provides configureStore with sensible defaults like built-in middleware, DevTools integration, and immutable state checks. The deprecation reflects the shift toward modern Redux patterns that reduce boilerplate and prevent common configuration errors.

Should I use legacy_createStore or migrate to configureStore?

You should prioritize migrating to configureStore from Redux Toolkit for new development and during major refactoring. Use legacy_createStore only as a temporary measure when you need to suppress deprecation warnings in legacy codebases that cannot immediately migrate large store configurations, with the understanding that both functions eventually point toward the same modernization path.

Do createStore and legacy_createStore return different store objects?

No, both functions return identical store objects with the same methods (dispatch, subscribe, getState, replaceReducer, and [Symbol.observable]). The legacy_createStore wrapper immediately delegates to createStore with the same arguments, ensuring behavioral parity while only differing in the deprecation warning presentation.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →