我有一个运行 redux 和 thunk 的 React 应用程序,一切都运行良好。我需要在页面重新加载时保留存储状态,以便数据不会丢失,因此创建了一个函数,该函数将数据存储在本地存储中,然后返回准备添加到 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
我原来运行的代码:
const store = createStore(reducers, applyMiddleware(thunk) );
我尝试修复此问题,遵循我在网上发现的一些类似问题,编译但破坏了最初工作正常的站点代码:
const composeEnhancers = LoadState || compose;
const store = createStore(reducers, composeEnhancers( applyMiddleware(thunk) ) );
//Error: Actions must be plain objects. Use custom middleware for async actions.
不确定我需要更改什么才能使其正常工作,非常感谢任何帮助。