Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when handleActions' map doesn't contain entries #173

Closed
ruszki opened this issue Nov 30, 2016 · 3 comments
Closed

Error when handleActions' map doesn't contain entries #173

ruszki opened this issue Nov 30, 2016 · 3 comments

Comments

@ruszki
Copy link
Contributor

ruszki commented Nov 30, 2016

Hi,

When an empty map is passed to handleActions, then Redux is failed because undefined will be returned for undefined state input. This has been already indicated in the discussion of #167 by @geminiyellow. The error message:

Uncaught Error: Reducer "somekeyinsomestateobject" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined.

The message comes from Redux, but the problem is caused by implementation of redux-actions' handleActions.

Of course there are not many useful use-cases for an empty map. Reducers of such handleActions basically mean that their associated state elements are unmodifiable, which is not recommended, as far as I know. It can be a "feature", but then the documentation should be updated indicating this mandatory condition.

@ruszki ruszki changed the title Error when handleActions' map doesn't contain element Error when handleActions' map doesn't contain entries Nov 30, 2016
@yangmillstheory
Copy link
Contributor

Would you mind submitting a pull request for the missing documentation? Should be a quick change.

@yangmillstheory
Copy link
Contributor

Why were you passing in an empty map before?

@ruszki
Copy link
Contributor Author

ruszki commented Nov 30, 2016

We started to transform our product to a React/Redux based site from a Thymeleaf based one. Now, the server generates an object which is used as an initial state by Redux. So some state elements are not yet under the control of Redux, and thus, they are read-only. We used handleActions({}, defaultState) as a dummy reducer. It was chosen to maintain consistency with other reducers, so it was just a matter of taste.

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

No branches or pull requests

2 participants