Skip to content

Adding an ability to see full state from a combined reducer #3664

Closed
@airlaser

Description

@airlaser

Do you want to request a feature or report a bug?

Feature

Prior Issues

None

New Features

What is the new or updated feature that you are suggesting?

I would like to see state - the entire, full state, not just the slice - passed as the 3rd argument to a reducer used in combinedReducers.

Why should this feature be included?

combineReducers is wonderful for creating nicely separated, logically consistent reducers. However, there's occasionally edge cases where it is justifiable for one reducer to need data from another. Right now it requires some messy code, either special casing a middleware to attach additional data, arbitrarily getting the store, or awkwardly pulling in extra data to an action when it's created.

With state as a 3rd arg it would be possible to grab the required data easily and cleanly. I think this is actually the biggest downside of it as well, since it could encourage abusing this ability to write reducers that break outside their bounds more often than just edge cases.

It would be fully backwards compatible since no reducer expects a 3rd arg right now.

What docs changes are needed to explain this?

https://redux.js.org/api/combinereducers/ & maybe https://redux.js.org/basics/reducers/ 's section on combineReducers


The core code change for this is just a few characters, I wrote this when I realized I'd have to also update the types & tests but could do a PR for this if it's something that would be considered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions