Skip to content
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

reducer initial state #77

Open
Jbarget opened this issue Jan 14, 2018 · 7 comments
Open

reducer initial state #77

Jbarget opened this issue Jan 14, 2018 · 7 comments

Comments

@Jbarget
Copy link

Jbarget commented Jan 14, 2018

https://github.com/fac-12/FAC-Events-Search/blob/master/client/src/reducers/authReducer.js#L3

i find its always helpful to have values as the initial state so that you can easily see what the reducer is expected to look like

@shannonjensen
Copy link
Collaborator

I'm not exactly sure what you mean by this in this case. Before the user is authenticated or not, the state needs to be null. It then becomes false if the user is not authenticated or the associated user info object if the user is authenticated. This is how Stephen Grider did it in his Udemy course.

@shannonjensen
Copy link
Collaborator

Do you mean we should have all of the user object fields elucidated and set to null initially? Perhaps add a separate field for authenticated null, false or true?

@Jbarget
Copy link
Author

Jbarget commented Jan 15, 2018

similar to this:

export const initialState = {
  assetLocks: {},
  own: {},
  members: {},
  count: 0,
  isSubscribed: false
};

just allows you to actually have initial state and gives you an idea of whats to come

@Jbarget
Copy link
Author

Jbarget commented Jan 15, 2018

you want to make your reducers as futureproof as possible.
If it just returns one value then later down the line if you need to add something to it, it will be a fair bit harder

@Jbarget
Copy link
Author

Jbarget commented Jan 15, 2018

in the same breath you want your reducers to be as flat as possible as well

@shannonjensen
Copy link
Collaborator

Ah I see. Where would we put the initialState constant? in the reducer index.js? The initial state is set in each individual reducer file in the default values of the function but I see what you mean, just not sure where you would actually use that variable?

@Jbarget
Copy link
Author

Jbarget commented Jan 24, 2018

@shannonjensen each individual reducer will have its own initial state. I tend to put it at the top of each of the reducers' file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants