1

React hooks reducer code called twice.

Is this someone already faced?

When I was returning state from the reducer, I was updating values by accessing it from the state and then returning the state.

Which was creating one more update life cycle for the state and it was called twice.

skyboyer
  • 22,209
  • 7
  • 57
  • 64

1 Answers1

1

In React reducer, If you are not merging state which is returned, it will be updated twice.

return { ...state, newPropertyUpdates:"" }

This way it should be merged.