Thunk
Today I want to talk about another part of redux called Thunk. Thunk is extremely useful when is comes to altering state and making fetch calls using redux. Thank is a middleware that allows you to call action creators that return a function. You can also you the dispatch method whenever you need it inside of fetch calls like in the example below.
With fetch calls specifically, Thunk allows us to use dispatch as an argument and use full functions in our fetch calls. Once we hit dispatch it triggers the beginning of state change. Our JSON data is sent as a new state to the reducers.
This is possible because at the beginning of setting up this React.js with redux we set a variable of store to createStore(). Within createStore() is housed manageStore(The name of the component that hold the reducers) and applyMiddleware(thunk).
Using all this will make state management so much easier in your React.js apps. I highly recommend Thunk. Of course it is not always totally necessary, you could work around it but I believe it is definitely worth the setup time.