我无法解决这个问题

actions.js

export const UPDATE = "UPDATE";


utils.js

export default function createReducer(initialState, handlers) {
    return function reducer(state = initialState, action) {
        if (handlers.hasOwnProperty(action.type)) {
            return handlers[action.type](state, action)
        } else {
            return state
        }
    }
}


reducer.js

import createReducer from "../../lib/utils.js";
import * as actions from "./actions.js";

export const filter = createReducer({}, {

});


CombinedReducers.js

import {
    combineReducers
} from "redux";
import filter from "../container/filter/reducer.js";

export default combineReducers(Object.assign(
    filter,
));


那就是我尝试连接store的地方。

index.android.js

import React, { Component } from "react";
import {
  AppRegistry,
} from "react-native";
import {
  Provider
} from "react-redux";
import {
  createStore,
  applyMiddleware,
  compose,
} from "redux";
import {
  createLogger,
} from "redux-logger";
import reducer from "./src/lib/reducers.js";
import thunkMiddleware from "redux-thunk";
import App from "./src/config/App.js"

const loggerMiddleware = createLogger({ predicate: (getState, action) => __DEV__});

function configureStore(initialState) {
  const enhancer = compose(
    applyMiddleware(
      thunkMiddleware,
      loggerMiddleware,
    ),
  );
  return createStore(reducer, initialState, enhancer);
}

const store = configureStore({});

const HelloWorld = () => {
  <Provider store={store}>
    <App/>
  </Provider>
}
AppRegistry.registerComponent("...", () => HelloWorld);


而且我总是得到:


  商店没有有效的减速器
  确保传递给CombineReducers的参数是一个其值为减速器的对象。


我在这里做错了什么?我假设它的createReducer()函数?

最佳答案

问题在这里:

export default combineReducers(Object.assign(
    filter,
));


filter返回一个函数,而Object.assign返回该函数,并且combineReducers期望一个对象,其每个键都是化简键。

因此,您的代码应如下所示:

export default combineReducers(Object.assign({ filter } ));


要么

export default combineReducers({ filter });

08-15 18:35