concept async in category react

appears as: sync, An async
React Hooks in Action

This is an excerpt from Manning's book React Hooks in Action.

  • Taking care when using async and await within an effect.
  • Redux in Action

    This is an excerpt from Manning's book Redux in Action.

    By contrast, asynchronous, or async, actions are where you can add asynchronous code such as AJAX requests. When dispatching synchronous actions, you don’t have any room for extra functionality. Async actions provide a way to handle asynchronous operations and dispatch synchronous actions with the results when they become available. Async actions typically combine the following into one convenient package, which you can dispatch directly within your app:

    Listing 6.20. An async/await example
    export function fetchTasks() { return async dispatch => { #1 try { #2 const { data } = await api.fetchTasks(); #3 dispatch(fetchTasksSucceeded(data)); } catch (e) { dispatch(fetchTasksFailed(e)); } } } #1 Adds the async keyword to the anonymous function #2 One error handling strategy is to use a try/catch block. #3 Uses the await keyword to block the function until the value returns !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":55},{\"line\":1,\"ch\":57}],[{\"line\":11,\"ch\":0},{\"line\":11,\"ch\":2}],[{\"line\":2,\"ch\":55},{\"line\":2,\"ch\":57}],[{\"line\":12,\"ch\":0},{\"line\":12,\"ch\":2}],[{\"line\":3,\"ch\":55},{\"line\":3,\"ch\":57}],[{\"line\":13,\"ch\":0},{\"line\":13,\"ch\":2}]]"} !@%STYLE%@!