相关疑难解决方法(0)

React Redux - 将多个存储增强器传递给 createStore() 时出错

我有一个运行 redux 和 thunk 的 React 应用程序,它一直运行良好。我需要在页面重新加载时保持存储状态,以便数据不会丢失,因此创建了一个将数据存储在 localstorage 中的函数,然后返回准备添加到 createStore 的数据(https://stackoverflow.com/a/ 45857898/801861)。数据存储工作正常并返回准备设置状态的对象。在 createStore 中添加数据对象时,反应无法编译并出现此错误:

错误:看起来您正在将多个商店增强器传递给 createStore()。这不受支持。相反,将它们组合成一个函数

这是当前代码返回错误:

const store = createStore(reducers, LoadState, applyMiddleware(thunk) );

//Error: It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function
Run Code Online (Sandbox Code Playgroud)

我正在运行的原始代码:

const store = createStore(reducers, applyMiddleware(thunk) );
Run Code Online (Sandbox Code Playgroud)

我试图在我在网上找到的一些类似问题之后解决这个问题,编译但破坏了最初工作正常的站点代码:

const composeEnhancers = LoadState || compose;
const store = createStore(reducers, composeEnhancers( applyMiddleware(thunk) ) );
//Error: Actions must be plain objects. Use custom …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs redux-thunk react-redux redux-store

7
推荐指数
3
解决办法
6191
查看次数

标签 统计

node.js ×1

react-redux ×1

reactjs ×1

redux-store ×1

redux-thunk ×1