August 2017
Beginner
374 pages
10h 41m
English
You may wonder what exactly the thunk middleware does. In fact, it is a very short function that checks whether an action is a function (that means whether we returned a function from an action creator). If that is the case, we call the function with dispatch and getState; otherwise, we simply call next:
const thunk = store => next => action => typeof action === 'function' ? action(store.dispatch, store.getState) : next(action)
It looks pretty simple, huh? Middleware is a simple, but powerful concept.
Read now
Unlock full access