Skip to content

Instantly share code, notes, and snippets.

@asherccohen
Last active May 9, 2020 23:23
Show Gist options
  • Save asherccohen/f4c05f6317c74f9e863648c248ebf052 to your computer and use it in GitHub Desktop.
Save asherccohen/f4c05f6317c74f9e863648c248ebf052 to your computer and use it in GitHub Desktop.
import { combineReducers } from 'redux';
import AppReducer from './AppReducer';
import UsersReducer from './UsersReducer';
import OrderReducer from './OrderReducer';
import NotificationReducer from './NotificationReducer';
import CommentReducer from './CommentReducer';
const appReducer = combineReducers({
/* your app’s top-level reducers */
users: UsersReducer,
orders: OrderReducer,
notifications: NotificationReducer,
comment: CommentReducer,
});
const rootReducer = (state, action) => {
// when a logout action is dispatched it will reset redux state
if (action.type === 'USER_LOGGED_OUT') {
// we keep a reference of the keys we want to maintain
// other keys will be passed as undefined and this will call
// reducers with an initial state
const { users, comment } = state;
state = { users, comment };
}
return appReducer(state, action);
};
export default rootReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment