0
votes

Currently I have a React/Redux reducer that looks like this:

export const INITIAL_STATE = {
  inputs: {},
};

export default function (state = INITIAL_STATE, action) {
  switch (action.type) {
    case planInputTypes.CLEAR_PLAN_INPUTS:
      return {
        ...state,
        inputs: {},
      };
    case planInputTypes.ADD_PLAN_INPUT:
      return set(`inputs.${action.payload.id}`, action.payload.inputData, state)
    default:
      return state;
  }
}

However, upon triggering CLEAR_PLAN_INPUTS, if action.payload.id == 0, then I would like to set action.payload.inputData back to defaultInput.

const defaultInput = {
  tableOne: {},
  tableTwo: {},
}

export const INITIAL_STATE = {
      inputs: defaultInput,
    };
    
    export default function (state = INITIAL_STATE, action) {
      switch (action.type) {
        case planInputTypes.CLEAR_PLAN_INPUTS:
          return {
            ...state,
            inputs: defaultInput,
          };
      }
    }

But, when I do that, it clears out the entire input object, when I only wanted to clear out the input object where input.planId === 0 object.