function preserveValuesFromState(state, preserveSetting, nextState) {
  // Return result of function if preserve is a function
  if (typeof preserveSetting === 'function') {
    return preserveSetting(state, nextState)
  }

  // Return original state if preserve is true
  if (preserveSetting === true) {
    return nextState ? { ...state, ...nextState } : state
  }

  if (Array.isArray(preserveSetting)) {
    return pick(state, preserveSetting) // pick returns a new object
  }

  throw new Error(
    'Invalid preserve parameter. It must be an Object or an Array'
  )
}
Preserve values from redux state change
@param {object} state - Redux state
@param {Function|boolean|Array} preserveSetting - Setting for which values to preserve
from redux state
@param {object} nextState - Next redux state
@returns {object} State with values preserved