A helper for the REQUEST/SUCCESS/FAILURE action creator pattern found in Redux.
Utilizes deox to provide strong TypeScript inferences.
Helps reduce boilerplate when making asynchronous API calls in Sagas or Thunks.
// saga.ts
function* fetchFooSaga({ meta }: ReturnType<typeof fetchFoo.trigger>) {
const { id } = meta;
try {
const foo = yield call(api, id);
yield put(fetchFoo.success(foo, meta));
} catch (error) {
yield put(fetchFoo.failure(error, meta));
}
}
export function* fooSaga() {
yield takeEvery(fetchFoo.TRIGGER, fetchFooSaga);
}
// Component.tsx
dispatch(fetchFoo.trigger({ id: '5' }))