question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrapping reducer in handleAction throws undefined state

See original GitHub issue

If 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:closed
  • Created 8 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
timchecommented, Jun 21, 2016

Thanks for the reminder @yangmillstheory 👍

0reactions
KalidassM01commented, Oct 23, 2020

You have to add default: return state; at the bottom of all cases of your switch function. Hope this work. Good luck

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found