React开发技巧总结

1. http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_one_basic_usages.html

combineReducers()做的就是产生一个整体的 Reducer 函数。该函数根据 State 的 key 去执行相应的子 Reducer,并将返回结果合并成一个大的 State 对象。

下面是combineReducer的简单实现。


const combineReducers = reducers => {
  return (state = {}, action) => {
    return Object.keys(reducers).reduce(
      (nextState, key) => {
        nextState[key] = reducers[key](state[key], action);
        return nextState;
      },
      {} 
    );
  };
};
你可以把所有子 Reducer 放在一个文件里面,然后统一引入。


import { combineReducers } from 'redux'
import * as reducers from './reducers'


const reducer = combineReducers(reducers)

你可能感兴趣的:(前端框架,react)