-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
Document required default state in reducer #1617
Comments
What can we do better? I think we’re already warning if you forgot to specify the initial state—is the warning not descriptive, or misleading? |
The warning simply tells me that nav is not returning state. I console logged the state at that point, being confused that I had passed initialState into createStore. It was being hit because of the INIT action from Redux, which passes state as undefined no matter what. So really the docs need to specify that default declaration is required when making a reducer (even if its just empty object, string, etc) |
@DaveStein : you might want to read through http://stackoverflow.com/questions/33749759/read-stores-initial-state-in-redux-reducer , which covers how reducer default state and This probably should go in the FAQ. I think I may have skipped it because I was considering putting it in a "Structuring Reducers", page, which I decided not to do as part of the initial FAQ work. |
@markerikson I would agree :) Going through Stack to find answers is unexpected. I did get the actual help via the IRC for #reactjs. I know the pain of trying to get docs write for people while also working on the thing you are doc'ing. But at least noobs like me point out what might need improvement haha |
I guess another source of confusion is that while the reducers section says "Redux will call our reducer with an undefined state for the first time", it is unclear that it maintains that even if createStore has the default state, which is optional. Stores come after that page so I assumed it would override that behavior. So my assumption was very wrong. |
Yeah,
It is implied that you never write Maybe we should rename it to |
This explains some reasoning behind it: http://stackoverflow.com/questions/33749759/read-stores-initial-state-in-redux-reducer/33791942#33791942 |
Added to the docs at http://redux.js.org/docs/recipes/reducers/InitializingState.html . |
Related to my pitfall here: http://stackoverflow.com/questions/36631728/why-isnt-combinereducers-receiving-state-in-redux/36633079#36633079
The docs show reducers having a default value for
state
, but it is never listed as required. The fact that an INIT action is fired beforecreateStore
takes advantage ofinitialState
was confusing.The text was updated successfully, but these errors were encountered: