1. Why use Redux middleware?
We don’t want a reducer to do side effects
so we use middleware (that can do anything), so the reducer doesn’t have to.
2. Consider the Redux Async Data Flow Diagram. Describe the flow in your own words.
A user hits a button, which sets off a dispatch to a middleware that makes an API request, which triggers a real dispatch action for the reducer, which returns a brand-new state.S
3. How are we accommodating async in our Redux app?
We’re using Thunk middleware to reuse logic without having to know which redux store we’re using beforehand.
1. Why would you need redux-thunk
middleware?
We use thunk, so we can do side-effects on a dispatch action outside of a reducer.
2. Redux Thunk middleware allows you to write action creators that return a ________ instead of an action.
function
3. Describe how any return value from the inner thunk function will be made available.
Return from inner functions will be available as return values of dispatch
itself
1. Looking ahead at this module’s course schedule, What do you look forward to learning?
2. What are your learning goals after reading and reviewing the class README?
-
Thunk
: the purpose of this is to re-dispatch actions
for middleware
The thunk
function can get around the object/function check by currying three times
const thunk = (store) => (next) => (action)=>
{
// so, the thunk does get hit twice, but the second time around, it sees that it's just an object, so it lets the action pass by
return typeof(action) === 'function'
? action(store.dispatch, store,getState)
: next(action)
}