How to update single value inside specific array item in redux

前端 未结 8 1422
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 01:55

I have an issue where re-rendering of state causes ui issues and was suggested to only update specific value inside my reducer to reduce amount of re-rendering on a page.

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 02:35

    In my case I did something like this, based on Luis's answer:

    ...State object...
    userInfo = {
    name: '...',
    ...
    }
    
    ...Reducer's code...
    case CHANGED_INFO:
    return {
      ...state,
      userInfo: {
        ...state.userInfo,
        // I'm sending the arguments like this: changeInfo({ id: e.target.id, value: e.target.value }) and use them as below in reducer!
        [action.data.id]: action.data.value,
      },
    };
    
    

提交回复
热议问题