What is the shortest way to modify immutable objects using spread and destructuring operators

前端 未结 6 1085
无人及你
无人及你 2021-01-30 22:34

I\'m looking for a pure function, to modify my immutable state object. The original state given as parameter must stay untouched. This is especially useful when working with fra

6条回答
  •  天涯浪人
    2021-01-30 23:23

    Removing item from an array, just use filter ;)

    CASE 'REMOVE_ITEM_SUCCESS':
    
          let items = state.items.filter(element => element._id !== action.id);
    
          return {
                ...state, 
                items
          }
    

提交回复
热议问题