ReactNative中如何用Redux Toolkit移除serializableStateInvariant中间件并导入依赖?
serializableStateInvariant Middleware & Import thunk/immutableStateInvariant in Redux Toolkit First off, you don't need to install any extra packages for these middlewares—they're all built into Redux Toolkit already. Here's exactly how to set this up:
Step 1: Import the required utilities
You can directly import thunk and immutableStateInvariant from @reduxjs/toolkit, along with configureStore:
import { configureStore, thunk, immutableStateInvariant } from '@reduxjs/toolkit'; import rootReducer from './path/to/your/rootReducer';
Step 2: Configure your store with the desired middlewares
Now you can pass the array of middlewares you want to use to the configureStore call. This will replace the default middleware list entirely, excluding serializableStateInvariant:
const store = configureStore({ reducer: rootReducer, middleware: [thunk, immutableStateInvariant] });
A more flexible alternative (recommended)
Instead of manually listing all the middlewares you want to keep, you can use getDefaultMiddleware to modify the existing list—this way you retain other default middlewares while only removing serializableStateInvariant:
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'; import rootReducer from './path/to/your/rootReducer'; const store = configureStore({ reducer: rootReducer, middleware: (getDefaultMiddleware) => getDefaultMiddleware().filter(middleware => middleware !== 'serializableStateInvariant') });
This approach is cleaner because you don't have to manually maintain a list of all middlewares you want to keep as Redux Toolkit updates.
内容的提问来源于stack exchange,提问作者Ryan Pergent

