Created
October 22, 2018 19:10
-
-
Save baso53/6ae0bd54f69eb040db4fba9de9ec6fcb to your computer and use it in GitHub Desktop.
implementing-sagas-sagas-1
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 { 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