0

Recently I stumbled upon the codebase where every reducer looks like the following. I guess they are spreading initialState to get rid of some 'leftover' nested state when reducer initialises, but is it meaningful?

const initialState = {...}

const reducer = (state = {...initialState}, action) => {
  ...
}
firedev
  • 20,898
  • 20
  • 64
  • 94

1 Answers1

0

If your reducer doesn't violate immutability principle, spreading an initialState does not make any sense, since reducer returns a new state (e.g. using aforementioned spread operator) on every action anyway.

oozywaters
  • 1,171
  • 1
  • 8
  • 17