Skip to content

Instantly share code, notes, and snippets.

View nomrik's full-sized avatar

Omri Kochavi nomrik

View GitHub Profile
@nomrik
nomrik / API_flow_saga.md
Last active April 19, 2023 20:18
API requests flow with Redux Saga

API requests flow

Introduction

In Redux, API requests are considered side effects, outside the regular Redux flow. Thus, they are normally handled by a middleware. Out of the many libraries available, one of the most popular is Redux Saga. Redux Saga has two main advantages over the other options:

  • It is built around JavaScript's generator functions, which make it possible to write async logic in a way that is easy to reason about.
  • It is easy to test.
  • When using it, all of the Redux actions are always just plain objects, unlike other middleware libraries which require async actions to be functions. That way it is possible to keep the standard Redux Flow, dispatching just regular actions. If the action is supposed to trigger async logic, the middleware will handle it.

This document is meant to descr