Reading 38 Remote APIs - liz-kavalski-401-advanced-javascript/seattle-javascript-401n13 GitHub Wiki

Async Actions

  • Two crucial moments in time: the moment you start the call, and the moment when you receive an answer (or a timeout).
  • Need to dispatch normal actions that will be processed by reducers synchronously.
  • The API request you'll want to dispatch at least three different kinds of actions.
    • An action informing the reducers that the request began.
      • The reducers may handle this action by toggling an isFetching flag in the state. This way the UI knows it's time to show a spinner.
    • An action informing the reducers that the request finished successfully.
      • The reducers may handle this action by merging the new data into the state they manage and resetting isFetching. The UI would hide the spinner, and display the fetched data.
    • An action informing the reducers that the request failed.
      • The reducers may handle this action by resetting isFetching. Additionally, some reducers may want to store the error message so the UI can display it.
  • For more information click the link

Redux Thunk

  • There are two very popular middleware libraries that allow for side effects and asynchronous actions: Redux Thunk and Redux Saga.
  • Redux Thunk is a middleware that lets you call action creators that return a function instead of an action object.
  • A thunk is a concept in programming where a function is used to delay the evaluation/calculation of an operation.
  • The most common use-case for Redux Thunk is for communicating asynchronously with an external API to retrieve or save data.
  • For examples and more in for click the link

Suspense (alpha/beta)

  • Suspense is a new React feature that aims to help with handling async operations respectively in regard to CPU power and data fetching.
  • Suspense allows you to defer rendering part of your application tree until some condition is met.
  • For demos and more for more infomation click this link