Redux Persist + Redux 工具包 $CombinedState 错误 [英] Redux Persist + Redux toolkit $CombinedState error

查看:45
本文介绍了Redux Persist + Redux 工具包 $CombinedState 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 redux persist 添加到 redux 工具包,但由于某种原因,我得到了一个 Exported 变量 'store' has or is using name '$CombinedState' from external module ".../node_modules/redux/索引"但不能命名. vscode 错误.

I'm trying to add redux persist to redux toolkit but for some reason I get an Exported variable 'store' has or is using name '$CombinedState' from external module ".../node_modules/redux/index" but cannot be named. error on vscode.

这是我的商店配置文件,添加了持久配置,如果我将其删除,则可以正常工作.

This is my store configuration file with the added persist config, which if I remove, works fine.

import { configureStore } from "@reduxjs/toolkit";
import { persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import { createEpicMiddleware } from "redux-observable";
import rootEpic from "onsite/redux/rootEpic";
import rootReducer from "onsite/redux/rootReducer";

const epicMiddleware = createEpicMiddleware();

const persistConfig = {
  key: "root",
  storage: storage,
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

// Line that shows error
const store = configureStore({
  reducer: persistedReducer,
  middleware: [epicMiddleware],
});

export default store;

epicMiddleware.run(rootEpic);

我尝试过的其他事情是将 combineReducers 声明(来自 rootReducerimport)放入同一个文件或将文件转换为普通的 javascript,结果相同或相似.出于某种原因,打字稿决定仍然在 javascript 文件上困扰我 :)

Other things I have tried are putting the combineReducers declaration (from rootReducerimport) into the same file or converting the file into plain javascript, with same or similar results. For some reason typescript decides to still haunt me on a javascript file :)

代码仍在运行,所以我很想保留它,但我想摆脱它.

The code still runs, so I'm tempted to leave it like that, but I would like to get rid of it.

推荐答案

添加一个

import { $CombinedState } from '@reduxjs/toolkit'

在该文件中通常应解决该错误.

in that file should usually resolve that error.

这篇关于Redux Persist + Redux 工具包 $CombinedState 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆