Wrapping reducer in handleAction throws undefined state
See original GitHub issueIf I wrap a reducer in handleAction
I get this error:
“Reducer “selectedReddit” 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.”
If I debug I see redux tries to get a initial state by calling the wrapped reducer with undefined state and a specific system action type. Because the type does not match the wrapped one the inner reducer never runs and no state default is created.
If I use handleActions
(m) with default state it works fine. Same function with default state in arguments and classic action-type check is also fine.
Anyway,is handleAction
usable like this? Readme doesn’t really specifiy use case.
Issue Analytics
- State:
- Created 8 years ago
- Comments:16 (3 by maintainers)
Top Results From Across the Web
handleAction(s) - redux-actions
Wraps a reducer so that it only handles Flux Standard Actions of a certain type. ... If either next() or throw() are undefined...
Read more >Reducer returns state as 'undefined' during Unit Testing with ...
I have added a wrapper.Update(). Is there anything that I am doing wrong in the below test case. import React from ' ...
Read more >React hooks (v17.0.3) and Redux handbook using TypeScript ...
When the function component wrapped inside of useMemo accepts a ... The type of the reducer function is Reducer<State | undefined, Action> ....
Read more >How to use React Context effectively - Kent C. Dodds
In Application State Management with React, I talk about how using a mix ... Consumer> {context => { if (context === undefined) {...
Read more >Read The Complete Redux Book (2nd edition) | Leanpub
Since each of the reducers calculates a new state (or returns the original ... Each reducer receives that action together with the undefined...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the reminder @yangmillstheory 👍
You have to add default: return state; at the bottom of all cases of your switch function. Hope this work. Good luck