Blog>
Snippets

Configuring Redux Store

Demonstrate how to create a Redux store using createStore, combining reducers and applying middleware.
import { createStore, applyMiddleware, combineReducers } from 'redux';
import thunk from 'redux-thunk';
import logger from 'redux-logger';
import authReducer from './reducers/authReducer';
import profileReducer from './reducers/profileReducer';

// Combining multiple reducers
const rootReducer = combineReducers({
  auth: authReducer,
  profile: profileReducer
});

// Applying middleware
const middlewareEnhancer = applyMiddleware(thunk, logger);

// Creating the Redux store with reducers and middleware
const store = createStore(
  rootReducer,
  middlewareEnhancer
);

export default store;
This code sets up the Redux store by combining multiple reducers into a single rootReducer using 'combineReducers'. Middleware such as thunk and logger are applied to the store to handle asynchronous actions and to log actions to the console, respectively. The 'createStore' function is used to initialize the store with the rootReducer and middleware.