-
-
Save designdevy/4a9c29cc4359eaec3f0484446b17c479 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 { ThunkAction } from 'redux-thunk'; | |
import { ApplicationState, ApplicationAction } from './types'; | |
import { loadUsersRequest, loadUsersSuccess, loadUsersError } from './actions'; | |
import * as userService from '../services/userService'; | |
type Effect = ThunkAction<any, ApplicationState, any, ApplicationAction>; | |
export const loadUsers = (): Effect => (dispatch, getState) => { | |
dispatch(loadUsersRequest()); | |
// assume userService.loadUsers returns a Promise<User[]> | |
return userService.loadUsers() | |
.then(users => dispatch(loadUsersSuccess(users))) | |
.catch(() => dispatch(loadUsersError())); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment