【问题标题】:Is reducer and global variable are the same?减速器和全局变量是一样的吗?
【发布时间】:2019-04-18 13:17:30
【问题描述】:

我可以像访问声明的javascript变量一样在浏览器控制台中获取reducer状态吗?

【问题讨论】:

    标签: react-redux reducers


    【解决方案1】:

    您可以使用中间件将 redux 状态存储在全局变量中。

        import { createStore, applyMiddleware } from 'redux';
    
        const stateInGlobal = store => next => action => {
          const result = next(action);
          window.reduxState = store.getState();
          return result;
        };
    
        const store = createStore(reducer, undefined, applyMiddleware(stateInGlobal))
    

    现在您可以通过变量 reduxState 访问 redux 状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-16
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多