Configuring the Redux Store with RTK 2.0 enhancements
Show how to set up the Redux store using the updated configureStore API provided by Redux Toolkit 2.0, which includes default middleware advancements and serialization checks.
import { configureStore } from '@reduxjs/toolkit';
import rootReducer from './reducers';
const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
// Ignore these field paths in all actions for serialization checks
ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
// Ignore these paths in the state for serialization checks
ignoredPaths: ['items.dates'],
},
immutableCheck: {
// Ignore these paths in the state for immutability checks
ignoredPaths: ['items.ignoreMutation']
}
}),
});
export default store;
This JavaScript code snippet imports the `configureStore` function from Redux Toolkit and sets up the Redux store. It specifies the root reducer and configures the default middleware with options for serialization and immutability checks, ignoring certain paths in actions and state that shouldn't be checked due to potential non-serializable values like Dates.
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Redux RTK 2.0 Example</title>
<script defer src='/path/to/your/compiled_javascript.js'></script>
</head>
<body>
<div id='app'>
<!-- Your app's HTML goes here -->
</div>
</body>
</html>
This HTML markup sets up a basic page with a script tag that will load the compiled JavaScript file containing the Redux store configuration. Make sure to replace '/path/to/your/compiled_javascript.js' with the actual path to your JavaScript file.
body {
font-family: 'Arial', sans-serif;
}
#app {
margin: 20px;
padding: 20px;
border: 1px solid #ddd;
}
This CSS snippet provides simple styling rules for the body of the webpage and the app's container div. It sets the font, margins, padding, and border for a clean presentation.