【问题标题】:Unable to use react-native-debugger after updating react-native更新 react-native 后无法使用 react-native-debugger
【发布时间】:2019-03-27 12:28:06
【问题描述】:

React Native 调试器应用版本:v0.8.1

React Native 版本:0.57.3

我收到了这个错误

It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function

在我从 0.55 更新之前它可以工作。

这就是我创建商店的方式。

import { createStore, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducers from '../reducers';

const store = createStore(
  reducers,
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
  compose(applyMiddleware(thunk)),
);

export default store;

当我使用 Chrome 进行调试时,它工作正常。

请帮忙,谢谢

【问题讨论】:

    标签: react-native redux react-native-debugger


    【解决方案1】:

    您需要传递两个参数,而不是传递三个参数给createStore 函数(其中一个用于预加载状态,我们在这里没有使用)。为了解决这个问题,在仍然使用 redux 开发工具的同时,您需要使用开发工具作为 composer 本身:

    import { createStore, compose, applyMiddleware } from 'redux';
    import thunk from 'redux-thunk';
    import reducers from '../reducers';
    
    const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
    
    const store = createStore(
      reducers,
      composeEnhancer(applyMiddleware(thunk)),
    );
    
    export default store;
    

    在挖掘了 redux 库、调试器应用程序和开发工具的源代码后,我意识到这是解决方案,并找到了这个部分:https://github.com/zalmoxisus/redux-devtools-extension#12-advanced-store-setup

    我还看到了一个几乎相同的问题on github,我认为这是您的问题,但我想我会在这里再次发布答案,以防有人在这里看到它。

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      因为我遇到了同样的问题,想使用 redux-devtools-extension,所以这里提供的解决方案无法 1:1 应用。这个人是如何适应这项工作的:

      import { applyMiddleware, combineReducers, createStore } from 'redux';
      import appConfigReducer from '../reducers/appConfigReducer';
      import logger from 'redux-logger'
      import { composeWithDevTools } from "redux-devtools-extension";
      
      const rootReducer = combineReducers(
        {config: appConfigReducer}
      );
      
      const composeEnhancers = composeWithDevTools({
        // options like actionSanitizer, stateSanitizer
      });
      
      const configureStore = () => {
        return createStore(rootReducer,
          composeEnhancers(applyMiddleware(logger))
        );
      };
      
      export default configureStore;
      

      【讨论】:

        猜你喜欢
        • 2020-02-15
        • 1970-01-01
        • 2020-11-24
        • 2018-05-08
        • 2021-01-23
        • 2020-11-26
        • 2022-01-26
        • 1970-01-01
        • 2021-12-09
        相关资源
        最近更新 更多