Blog>
Snippets

Using Redux DevTools Extension with Redux v5.0.0

Present how to integrate Redux DevTools Extension with a Redux v5.0.0 store configuration for debugging.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redux DevTools Example</title>
</head>
<body>
    <!-- The root element where your app will be rendered -->
    <div id="root"></div>
    <!-- Include your bundled scripts below, including Redux v5.0.0 -->
    <script src="path/to/your/bundled/scripts.js"></script>
</body>
</html>
This is the HTML structure required to render a Redux application. You will need to include your bundled JavaScript files which contain your Redux configuration and React components.
/* Redux v5.0.0 Store Configuration with Redux DevTools Extension Integration */

import { configureStore } from '@reduxjs/toolkit';

// Assume you have a rootReducer exported from another file
import rootReducer from './reducers';

// Store configuration with Redux DevTools Extension enabled
const store = configureStore({
  reducer: rootReducer,
  // Enable Redux DevTools if it is installed as a browser extension
  devTools: process.env.NODE_ENV !== 'production'
});

export default store;
This JavaScript snippet demonstrates how to create a Redux store using Redux Toolkit's configureStore function. It automatically sets up the Redux DevTools Extension if it is present in the browser.
/* Your root reducer, combining different reducers */

import { combineReducers } from '@reduxjs/toolkit';

// Import your individual reducers
import todosReducer from './todosReducer';
import userReducer from './userReducer';

const rootReducer = combineReducers({
    todos: todosReducer,
    user: userReducer,
});

export default rootReducer;
This JavaScript code combines different reducers into a single root reducer using Redux Toolkit's combineReducers function. Each key in the combineReducers argument object will represent a slice of your application state.
/* Example of a simple reducer */

const initialState = {};

function userReducer(state = initialState, action) {
  switch (action.type) {
    // Define actions to handle different types of actions
    default:
      return state;
  }
}

export default userReducer;
This JavaScript snippet provides a simple example of a reducer, which is a pure function that takes the current state and an action as arguments and returns a new state. The default case returns the current state if no applicable actions are dispatched.