How to compose redux reducers with dependent state

后端 未结 4 1798
别跟我提以往
别跟我提以往 2021-02-04 08:47

I am working on a React/Redux application that allows for \"widgets\" to be added to a page and manipulated in 2D space. It is a requirement that multiple widgets can be selecte

4条回答
  •  醉话见心
    2021-02-04 09:40

    I am using this:

    CommonReducer.js

    export default function commonReducer(state = initialState.doesNotMatter, payload) {
       switch (payload.type) {
         case "JOINED_TYPE": {
           let newState = Object.assign({}, state);
           return newState;
         }
         default:
           return state;
      }
    }
    

    SomeOtherReducer.js

    import commonReducer from './commonReducer';
    
    export default function someReducer(state = initialState.somePart, payload) {
           switch (payload.type) {
             case "CUSTOM_TYPE": {
               let newState = Object.assign({}, state);
               return newState;
             }
             default:{
               return commonReducer(state, payload);
             }
          }
    }
    

提交回复
热议问题