Using the Redux DevTools Extension
Implement support for the Redux DevTools Extension for easier state debugging and visualization.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redux DevTools Extension Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/4.0.5/redux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/7.1.3/react-redux.min.js"></script>
</head>
<body>
<div id="root"></div>
<script src="app.js"></script>
</body>
</html>
Basic HTML structure importing Redux and React-Redux from a CDN. The 'app.js' will contain the Redux store logic.
// app.js
// Import necessary Redux functions and reducers.
import { createStore, combineReducers } from 'redux';
import { yourReducer } from './reducers';
// Define the root reducer combining all reducers of your app
const rootReducer = combineReducers({
yourReducer,
// ...other reducers
});
// Configure the Redux DevTools Extension
const reduxDevTools =
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__();
// Create the store with the rootReducer and the Redux DevTools Extension enhancer
const store = createStore(rootReducer, reduxDevTools);
export default store;
This JavaScript code in 'app.js' sets up a Redux store that is connected to the Redux DevTools Extension. It first imports the necessary functions from Redux and any reducers the app uses. It then combines the reducers and connects the store to the Redux DevTools.