conorhastings / use-reducer-with-side-effects

MIT License
88 stars 18 forks source link

Bug: error thrown when dispatching an `Update()` #7

Closed jamesplease closed 5 years ago

jamesplease commented 5 years ago

Type: Bug Library version: 1.0.0

What's happening?

I'm creating a reducer and dispatching an Update(). This is throwing the following error:

index.js:70 Uncaught TypeError: newSideEffect is not iterable

This is the LoC throwing the error

What's the expected behavior?

This would not error.

What's the source of the problem?

I believe this problem was introduced in eac6b68efa53f9 and then almost but not quite fixed in 54e75bf342 . Currently, the LoC that are throwing the error don't do anything.

Possible resolution

There are a bunch of ways to fix this, one is:

const newSideEffects = newSideEffect
      ? [
          ...state.sideEffects,
          ...(Array.isArray(newSideEffect) ? newSideEffect : [newSideEffect]),
        ]
      : state.sideEffects;