Blog>
Snippets

Migrating to Redux Toolkit's configureStore

Demonstrate how to replace the deprecated createStore with configureStore from Redux Toolkit, including the basic setup and incorporation of middleware and enhancers.
import { configureStore } from '@reduxjs/toolkit';
import rootReducer from './reducers';

// Configure store with reducers and optional middleware/enhancers
const store = configureStore({
  reducer: rootReducer,
  // You can include middleware as an array
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(/* your custom middleware here */),
  // You can also add enhancers here if needed
  enhancers: [/* your custom enhancers here */]
});

export default store;
This code replaces the deprecated createStore with configureStore from Redux Toolkit. It imports configureStore, sets up the root reducer, and allows for inclusion of middleware and enhancers.