Last active
December 9, 2018 16:16
-
-
Save ilonacodes/5c199385bd6a44e17c8c7b1e035f0ad7 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 axios from 'axios'; | |
import { put, takeLatest } from 'redux-saga/effects' | |
import {actions, t} from './actions'; | |
// the base URL for your REST API backend | |
const baseUrl = 'https://api.github.com/users'; | |
// sending request with username and getting user data from GitHub | |
function* loadUserData(action) { | |
const response = yield axios.get(`${baseUrl}/${action.name}`); | |
yield put(actions.loadUserDataSuccess(response.data)) | |
} | |
// watches for actions dispatched to the store and starts loadUserData saga | |
export function* watchLoadUserData() { | |
yield takeLatest(t.LOAD_USER_DATA, loadUserData) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment