Blog>
Snippets

Converting createStore to configureStore

Show a side-by-side code example that transforms a Redux store initialization from createStore to the Redux Toolkit's configureStore method.
import { createStore, applyMiddleware } from 'redux';
import rootReducer from './reducers';
const store = createStore(
  rootReducer,
  applyMiddleware(...middlewares)
);
This is the original way to initialize a Redux store using createStore with middleware applied.
import { configureStore } from '@reduxjs/toolkit';
const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(...middlewares)
});
This is the refactored way to initialize a Redux store using the configureStore method from Redux Toolkit with middleware applied.