Cleaner/shorter way to update nested state in Redux?

前端 未结 6 705
鱼传尺愫
鱼传尺愫 2020-11-28 06:22

Sometimes reducers get kind of messy:

const initialState = {
    notificationBar: {
        open: false,
    },
};

export default function (state = initialS         


        
6条回答
  •  无人及你
    2020-11-28 07:03

    If you're using Immutable.js, you can look under Nested Structures topic some functions that may help you, I personally use mergeDeep:

    prevState.mergeDeep({ userInfo: {
      username: action.payload.username,
    } }),
    

提交回复
热议问题