Skip to content

Instantly share code, notes, and snippets.

@smks
Last active December 2, 2018 13:11
Show Gist options
  • Save smks/e60005fe26f2f39202c5ce2dd6a9cf64 to your computer and use it in GitHub Desktop.
Save smks/e60005fe26f2f39202c5ce2dd6a9cf64 to your computer and use it in GitHub Desktop.
Saga for people.js
import { call, put, takeEvery } from 'redux-saga/effects';
import API from '../services/api';
import { getPeople } from '../actions';
export function* callPeopleService() {
return yield call(API.getPeople);
}
export function* getPeopleRequest() {
try {
const { data } = yield call(callPeopleService);
yield put(
getPeople.success({
people: data,
}),
);
} catch (error) {
yield put(getPeople.failure(error.message));
}
}
export default function* peopleSaga() {
yield takeEvery(getPeople.REQUEST, getPeopleRequest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment