Cleaner/shorter way to update nested state in Redux?

前端 未结 6 704
鱼传尺愫
鱼传尺愫 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 06:37

    UPD: it's now a part of the ES2018

    It might be slightly improved via a non-standardised yet properties spread syntax:

    return {
        ...state,
        notificationBar: {
            ...state.notificationBar,
            open: true,
        },
    };
    

提交回复
热议问题