How to update single value inside specific array item in redux

前端 未结 8 1419
隐瞒了意图╮
隐瞒了意图╮ 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:27

    You can use map. Here is an example implementation:

    case 'SOME_ACTION':
       return { 
           ...state, 
           contents: state.contents.map(
               (content, i) => i === 1 ? {...content, text: action.payload}
                                       : content
           )
        }
    

提交回复
热议问题