How do I add an element to array in reducer of React native redux?

前端 未结 4 748
予麋鹿
予麋鹿 2020-12-22 16:52

How do I add elements in my array arr[] of redux state in reducer? I am doing this-

import {ADD_ITEM} from \'../Actions/UserActions\'
const ini         


        
4条回答
  •  -上瘾入骨i
    2020-12-22 17:32

    I have a sample

    import * as types from '../../helpers/ActionTypes';
    
    var initialState = {
      changedValues: {}
    };
    const quickEdit = (state = initialState, action) => {
    
      switch (action.type) {
    
        case types.PRODUCT_QUICKEDIT:
          {
            const item = action.item;
            const changedValues = {
              ...state.changedValues,
              [item.id]: item,
            };
    
            return {
              ...state,
              loading: true,
              changedValues: changedValues,
            };
          }
        default:
          {
            return state;
          }
      }
    };
    
    export default quickEdit;
    

提交回复
热议问题