Now for that, I will install one extra package in this project with npm install --save and that's
Redux Thunk.
That's a so-called Redux middleware which we can call, which allows us to change our action creators
here in the actions folder such that we can actually do asynchronous stuff there, that we can handle
side effects there so that we can for example send HTTP requests in such an action creator and only once
that HTTP requests is done,
we're actually dispatching an action to the Redux store because that's important,
your Redux flow in general needs to be synchronous. So you can't wait for some action to complete before
you update your state. With Redux Thunk, that changes, your reducer still needs to be synchronous,
so no async code must be in here but your action creator can now be asynchronous,
this means that you now can send a request as part of your action creator and only once you're done
with that, you actually dispatch the action to the reducer and you'll see this in practice in a second,
for example here in create product which is the thing I want to start with.
However to use this new feature, we have to enable Redux Thunk and we do this in the app.js file, there
from Redux,
you need to import apply middleware and in addition, you need to import a new thing and that's Redux
Thunk, you can name this however you want, from Redux Thunk. Again
this can be named however you want because we're using the default export of that package.
Now you use that in create store, there you can parse a second argument and there, you should call
apply middleware as a function and to that function, pass Redux Thunk.
This will now basically enable that package which in turn allows us to do this different thing
in the action creator I was referring to and that different thing is now what we'll have a look at next.