fac-12 / FAC-Events-Search

Event Finder Prototype
http://fac-eventfinder.herokuapp.com
3 stars 0 forks source link

reducer initial state #77

Open Jbarget opened 6 years ago

Jbarget commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

shannonjensen commented 6 years ago

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 commented 6 years ago

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