Reading-Notes

Reading

async actions

Why use Redux middleware?

By itself, a Redux store doesn’t know anything about async logic. It only knows how to synchronously dispatch actions, update the state by calling the root reducer function, and notify the UI that something has changed. Any asynchronicity has to happen outside the store. Redux middleware were designed to enable writing logic that has side effects. Also, since middleware form a pipeline around the real store.dispatch function, this also means that we could actually pass something that isn’t a plain action object to dispatch, as long as a middleware intercepts that value and doesn’t let it reach the reducers.

https://redux.js.org/tutorials/fundamentals/part-6-async-logic

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

something is sent from state -> UI gets the deposit -> clickevent gets to the event handler -> goes to the middleware -> send out an API request -> gets an API response back to the middleware -> action type goes back into the store

How are we accommodating async in our Redux app?

A middleware called Redux Thunk

thunk middleware

Why would you need redux-thunk middleware?

With a plain basic Redux store, you can only do simple synchronous updates by dispatching an action. Middleware extends the store’s abilities, and lets you write async logic that interacts with the store.

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

“function”

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

“dispatch”

Reflection

What are your learning goals after reading and reviewing the class README?

I’m only kind of understanding it, hopefully seeing it in action will be helpful to understanding how it works.