Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 1.96 KB

401-class38.md

File metadata and controls

32 lines (20 loc) · 1.96 KB

Class 401.15

Notes

Readings

async actions

  1. Why use Redux middleware?

Redux middleware is used to handle side effects, such as interacting with an API. It allows you to write asynchronous logic that interacts with the store.

  1. Consider the Redux Async Data Flow Diagram. Describe the flow in your own words.

The Redux Async Data Flow starts with an action being dispatched. If it's an async action, it goes through the middleware which can process, delay or conditionally dispatch it. Once the middleware resolves, the reducer handles the action and updates the state which in turn updates the UI.

  1. How are we accommodating async in our Redux app?

Asynchronous actions in Redux are handled using middleware, like Redux Thunk. Middleware intercepts dispatched actions and can delay them, or dispatch different actions conditionally based on the state of the application or the results of API calls.

thunk middleware

  1. Why would you need redux-thunk middleware?

Redux Thunk middleware is needed when you want to write action creators that return a function instead of an action. This is useful for managing asynchronous tasks such as API calls or timers.

2.Redux Thunk middleware allows you to write action creators that return a ________ instead of an action.

Redux Thunk middleware allows you to write action creators that return a function instead of an action. These functions can dispatch actions and execute asynchronous code.

  1. Describe how any return value from the inner thunk function will be made available.

Any return value from the inner thunk function will be treated as the return value of the dispatch method. This allows you to wait for the thunk to complete and use its return value in the component. For example, dispatch(someThunk()).then(result => doSomethingWith(result)).

Things I want to learn more about

References

  • Google Bard and ChatGPT