3

React Native Debugger 应用程序版本: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 进行调试时,它工作正常。

请帮忙,谢谢

4

2 回答 2

13

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

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 -设置

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

希望这可以帮助!

于 2018-10-23T15:42:39.510 回答
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-01-15T13:04:47.943 回答