Reactjs asyncLocalStorage需要全局localStorage对象

Reactjs asyncLocalStorage需要全局localStorage对象,reactjs,redux,react-redux,server-rendering,Reactjs,Redux,React Redux,Server Rendering,我正在尝试使用redux persist持久化数据。这是我的密码: import { createStore as _createStore, applyMiddleware, compose } from 'redux'; import createMiddleware from './middleware/clientMiddleware'; import { routerMiddleware } from 'react-router-redux'; import {persistStore

我正在尝试使用
redux persist
持久化数据。这是我的密码:

import { createStore as _createStore, applyMiddleware, compose } from 'redux';
import createMiddleware from './middleware/clientMiddleware';
import { routerMiddleware } from 'react-router-redux';
import {persistStore, autoRehydrate} from 'redux-persist';

export default function createStore(history, client, data) {
  // Sync dispatched route actions to the history
  const reduxRouterMiddleware = routerMiddleware(history);

  const middleware = [createMiddleware(client), reduxRouterMiddleware];

  let finalCreateStore;
  if (__DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
    const { persistState } = require('redux-devtools');
    const DevTools = require('../containers/DevTools/DevTools');
    finalCreateStore = compose(
      applyMiddleware(...middleware),
      window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
      persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
    )(_createStore);
  } else {
    finalCreateStore = applyMiddleware(...middleware)(_createStore);
  }

  const reducer = require('./modules/reducer');
  // const store = finalCreateStore(reducer, data);
  const store = finalCreateStore(reducer, data, autoRehydrate());
  if (typeof window !== 'undefined') persistStore(store);

  if (__DEVELOPMENT__ && module.hot) {
    module.hot.accept('./modules/reducer', () => {
      store.replaceReducer(require('./modules/reducer'));
    });
  }

  return store;
}
它可以在单个流中正常工作。但若我在除主页之外的任何页面上刷新页面,页面上的一切都会受到干扰。我还收到了以下警告:

[1] redux-persist asyncLocalStorage requires a global localStorage object. Either use a different storage backend or if this is a universal redux application you probably should conditionally persist like so: https://gist.github.com/rt2zz/ac9eb396793f95ff3c3b
[1] Warning: React can't find the root component node for data-reactid value `.15mzo5h179c.3.0.0`. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.

另外,我正在使用样板文件

仅当您在客户端上运行时,才希望有条件地使用localStorage store enhancer创建存储

...
const reducer = require('./modules/reducer');
let store;

if (__CLIENT__) {
    store = finalCreateStore(reducer, data, autoRehydrate());
    persistStore(store);
} else {
    store = finalCreateStore(reducer, data);
}
...

也许可以尝试改为“if(typeof window!=='undefined')persistStore(store);”仍然是相同的问题?我应该分享完整的redux创建模块吗?是的,发布组成finalCreateStore函数的代码以及如何创建存储。我刚刚更新了我的问题,请看那里。谢谢。更新了我的答案,希望有帮助<代码>本地存储仅存在于浏览器上。