forked from thecodingmachine/react-native-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleSaga.js
25 lines (23 loc) · 794 Bytes
/
ExampleSaga.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { put, call } from 'redux-saga/effects'
import ExampleActions from 'App/Stores/Example/Actions'
import { userService } from 'App/Services/UserService'
/**
* A saga can contain multiple functions.
*
* This example saga contains only one to fetch fake user informations.
* Feel free to remove it.
*/
export function* fetchUser() {
// Dispatch a redux action using `put()`
// @see https://redux-saga.js.org/docs/basics/DispatchingActions.html
yield put(ExampleActions.fetchUserLoading())
// Fetch user informations from an API
const user = yield call(userService.fetchUser)
if (user) {
yield put(ExampleActions.fetchUserSuccess(user))
} else {
yield put(
ExampleActions.fetchUserFailure('There was an error while fetching user informations.')
)
}
}