Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why does a reducer needs a default state? #514

Closed
Labels
@pauldijou

Description

@pauldijou

I might be missing something, but I don't understand why a reducer should have a default state. Most of the doc have something like:

functionreducer(state=initialState,action){...}

I don't see why the reducer should know anything about the default state. The state is managed by the store, the reducer is a pure function that does its job with whatever you give it as argument and not trying to guess what the state is if there is none. But well, I though that it was ok as long as I wasn't forced to put a default state inside the reducer.

Except thatcombineReducers forces me to put a default state. According tothis code, anundefined state will be triggered by Redux to the reducer. Why? My store will pass the default state, so it will never beundefined in practice. My reducer is simple: if it knows the action, it will do something, if not, it will return the state. If the state isundefined, it will returnundefined.

Even worse, what if I want to use the same reducer in several different stores with different initial states? Agreed I can always put a fake default state inside the reducer (like0) and it will be overridden by the store default states, whatever they are, but it feels just wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp