Blog>
Snippets

Using Redux DevTools with New Middleware Approach

Illustrate the configuration changes required to use Redux DevTools with the new middleware approach in Redux v5.0.0.
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import rootReducer from './reducers';
import thunk from 'redux-thunk';

// Setup Redux store with thunk middleware and Redux DevTools
const store = createStore(
  rootReducer,
  composeWithDevTools(
    applyMiddleware(thunk)
    // other store enhancers if any
  )
);

export default store;
This code snippet shows how to set up a Redux store using the `redux-devtools-extension` package to incorporate the Redux DevTools extension. Thunk is used as an example middleware, and `composeWithDevTools` is wrapping the applyMiddleware call to enable the DevTools.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redux DevTools Example</title>
</head>
<body>
    <div id="app"></div>
    <script src="path_to_your_bundled_script.js"></script>
</body>
</html>
This HTML markup includes a div element with an id of 'app' where your React app will be rendered. The bundled JavaScript file that contains your Redux store setup with the new middleware approach and the rest of your React application is linked here.
body {
    margin: 0;
    font-family: Arial, sans-serif;
}

#app {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
This CSS provides basic styling for the HTML document. It sets a global font family, removes the default margin from the body, and centers the div with an id of 'app' both vertically and horizontally in the viewport.