Last active
March 23, 2019 12:34
-
-
Save rowlandekemezie/2c1823f442ecca28125528c1af907e54 to your computer and use it in GitHub Desktop.
Saga for making calls to gitHubApi
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
// Here, we use ES6 destructuring assignment to extract payload | |
// from the action object passed to it. | |
function* loadUserDetails({ payload }) { | |
try { | |
const user = yield call(gitHubApi, payload); | |
// Yields effect to the reducer specifying action type | |
// and user details. | |
yield put({type: 'LOAD_USER_SUCCESS', user}); | |
} catch (error) { | |
yield put({ type: 'LOAD_USER_FAILURE', error }); | |
} | |
} | |
// Call loadUserDetails with action's payload each time | |
// LOAD_USER_REQUEST is dispatched | |
function* watchRequest() { | |
yield takeLatest('LOAD_USER_REQUEST', loadUserDetails); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment