Skip to content

Instantly share code, notes, and snippets.

@baso53
Created October 22, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baso53/6ae0bd54f69eb040db4fba9de9ec6fcb to your computer and use it in GitHub Desktop.
Save baso53/6ae0bd54f69eb040db4fba9de9ec6fcb to your computer and use it in GitHub Desktop.
implementing-sagas-sagas-1
import axios from 'axios';
import { call, put } from './effects';
const fetchData = URL => axios.get(URL);
export function* fetchDataWorker(action) {
try {
const response = yield call(fetchData, `https://uinames.com/api/?gender=${action.payload}`);
yield put({ type: 'FETCH_DATA_SUCCESS', payload: response.data });
} catch (error){
yield put({ type: 'FETCH_DATA_FAILED', payload: error.message});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment