Last active
May 9, 2020 23:23
-
-
Save asherccohen/f4c05f6317c74f9e863648c248ebf052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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