I am refactoring my code to eliminate the default store and use ES6+ defaults as follows:
That is I am moving defaults from an object passed in as follows:
const store = createStore(reducers, defaultstore, middleware);
to directly into the reducers. This way I can locate them easier. The two methods are shown below ...
defaultstore
Menu: {
current: 'Articles'
},
reducer function
// People is the default
const Menu = (state = {current: 'People'}, action) => {
const newState = { ...state };
switch(action.type) {
case 'updateMenu':
newState.current = action.current;
return newState;
}
return state;
};
Is there any reason not to do this. It makes the code more readable.