Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Youtube in React: generic fetching function based on redux-saga
import {all, call, put} from 'redux-saga/effects';
... rest unchange for now
* entity must have a success, request and failure method
* request is a function that returns a promise when called
* */
export function* fetchEntity(request, entity, ...args) {
try {
const response = yield call(request);
// we directly return the result object and throw away the headers and the status text here
// if status and headers are needed, then instead of returning response.result, we have to return just response.
yield put(entity.success(response.result, ...args));
} catch (error) {
yield put(entity.failure(error, ...args));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.