Skip to content

HarryGogonis/redux-routines-ts

Repository files navigation

Redux-Routines-Ts

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.


Example Usage

// 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' }))

Inspired By

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published