-
-
Save designdevy/207272343fcc9ecdc226bd9a0ae258b1 to your computer and use it in GitHub Desktop.
This file contains 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 produce from 'immer'; | |
import { ApplicationState, ApplicationAction } from './types'; | |
export const initialState: ApplicationState = { | |
loading: { | |
users: false, | |
}, | |
users: [], | |
} | |
const reducer = (state = initialState, action: ApplicationAction) => { | |
switch (action.type) { | |
case "loadUsersRequest": | |
return produce(state, draft => { | |
draft.loading.users = true; | |
}); | |
case "loadUsersSuccess": | |
return produce(state, draft => { | |
draft.loading.users = false; | |
draft.users = action.users; | |
}); | |
case "loadUsersError": | |
return produce(state, draft => { | |
draft.loading.users = false; | |
}); | |
} | |
} | |
export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment