You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ReactNative中如何用Redux Toolkit移除serializableStateInvariant中间件并导入依赖?

How to Remove 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]
});

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 08:27:30