How to update single value inside specific array item in redux

前端 未结 8 1423
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  猫巷女王i
    2020-11-28 02:22

    You don't have to do everything in one line:

    case 'SOME_ACTION':
      const newState = { ...state };
      newState.contents = 
        [
          newState.contents[0],
          {title: newState.contnets[1].title, text: action.payload}
        ];
      return newState
    

提交回复
热议问题