Skip to content

Instantly share code, notes, and snippets.

@ilonacodes
Last active December 9, 2018 16:16
Show Gist options
  • Save ilonacodes/5c199385bd6a44e17c8c7b1e035f0ad7 to your computer and use it in GitHub Desktop.
Save ilonacodes/5c199385bd6a44e17c8c7b1e035f0ad7 to your computer and use it in GitHub Desktop.
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