softwaredev
softwaredev

Reputation: 40

How can I reset a piece of Redux, but maintain the rest?

I have a Redux reducer:

case inputTypes.CLEAR_INPUTS:
  const defaultCopyTwo = JSON.parse(JSON.stringify(defaultInput))
  return {
    ...state,
    inputs: {
      0: defaultCopyTwo
    }
  };

The logic that I'd like to have happen is that the 0th index of the inputs object gets reset to the defaults, but that the other indices don't get deleted. Currently, everything is getting cleared - not just the 0th index.

Upvotes: 0

Views: 34

Answers (1)

Robin Zigmond
Robin Zigmond

Reputation: 18249

I think this change should work as you intend?

  return {
    ...state,
    inputs: {
      ...state.inputs,
      0: defaultCopyTwo
    }
  };

Upvotes: 1

Related Questions