Last active
June 25, 2022 09:02
-
-
Save Calvin-Huang/53173f7835227f044dbbb163975d1b4f to your computer and use it in GitHub Desktop.
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 { takeEvery } from 'redux-saga'; | |
import { call, put } from 'redux-saga/effects'; | |
// Watcher | |
function* watchFetchData() { | |
yield* takeEvery('FETCH_REQUESTED', fetchData); | |
} | |
// Worker | |
function* fetchData(action) { | |
try { | |
const data = yield call(fetch, action.payload.url); | |
yield put({type: 'FETCH_SUCCEEDED', data}); | |
} catch (error) { | |
yield put({type: 'FETCH_FAILED', error}); | |
} | |
} | |
+export default function* rootSaga() { | |
+ yield all([ | |
+ fork(watchFetchData), | |
+ ]); | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment