Skip to content

Instantly share code, notes, and snippets.

@tanner-west
Created February 14, 2022 14:52
Show Gist options
  • Save tanner-west/b91d320b68108d26f6b368a41b2ed67f to your computer and use it in GitHub Desktop.
Save tanner-west/b91d320b68108d26f6b368a41b2ed67f to your computer and use it in GitHub Desktop.
function getUsersAsync() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([{ name: "Bob", age: 24 }, { name: "Alice", age: 50 }])
}, 3000)
})
}
export function* getUsersSaga() {
try {
const users = yield call(getUsersAsync);
yield put({ type: 'GET_USERS_SUCCEEDED', payload: users })
} catch (e) {
yield put({ type: 'GET_USERS_FAILED', payload: e })
}
}
export default function* rootSaga() {
yield all([
yield takeEvery('GET_USERS_REQUESTED', getUsersSaga)
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment