Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

setupCognito causes state mutation error when passing applyMiddleware to createStore #28

Open
HoraceShmorace opened this issue Sep 30, 2017 · 1 comment

Comments

@HoraceShmorace
Copy link

HoraceShmorace commented Sep 30, 2017

Issue
setupCognito doesn't seem to play nicely with Redux's applyMiddleware, resulting in a Redux state mutation error.

Steps to reproduce:

  1. Import applyMiddleware from redux.
  2. Call createStore, passing a call to applyMiddleware (which can be passed any middleware).
  3. Call setupCognito.

Symptom
This results in the following error:

Uncaught Error: A state mutation was detected between dispatches, in the path cognito.userPool.client.api.operations.addCustomAttributes.input.defaultValue. This may cause incorrect behavior. (http://redux.js.org/docs/Troubleshooting.html#never-mutate-reducer-arguments)
at invariant (browser.js:40)
at index.js:53
at Object.dispatch (index.js:14)
at setupCognito (react-cognito.js:1191)
at index.js:16

The error seems triggered by the call to setupCognito.

@HoraceShmorace
Copy link
Author

I'm not sure yet why this is only happening when using applyMiddleware, but I'm pretty sure you shouldn't store a class instance (cognito.userPool) in state since its properties are inherently mutable by its own methods (and thus, mutations can happen outside of a reducer).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant