Let's put together our cells action krater inside of our Action Creatures Index Ortez file inside of
here at the very top.
I'm going to import Axios right away, which we're going to use to make our network request.
I'm also going to find my import statement from the sell file, and once again, I'm going to also import
the cell interface because I suspect we're probably going to need it inside of your.
I'll then go down to the bottom, the file.
And we will add in a new action creator that we will call simply vetch cels.
Because we're going to be making a network request inside of your we're definitely going to want to
use Redux Thunk, it's going to make sure that Petch sells, is going to return a function.
And remember, that inner function is going to be called with our dispatch function.
So I will list out that argument of dispatch and I will annotate its type as dispatch.
Action and remember this whole thing we went through right here, we spoke about that at great length,
that type invitation is what's going to make sure that we can only call dispatch with a properly typed
action object.
I'm also going to mark this function right here as async, because we're going to make a network request
inside their.
And then finally, we can start to write out our actual request logic again, the first thing we probably
want to do is dispatch an action to say, hey, we are about to make a request here.
We created an action type specifically for that.
So I'm going to dispatch.
And action with a type of action type thought that sells.
Again, only purpose of this one is to flip that loading flag over to true.
Well, then put down a try catch statement.
We're going to make our request from inside of here.
So if anything goes wrong with the request, we can capture the error that occurred in dispatch.
Another action describing that fact.
Inside the try, let's first make a request, we'll do a request.
I'm going to d structure off the data property off of a weight axios Moorgate cels.
Now, remember, once again, this data thing right here, the state of property, that is the response
we get back from our API and as we just saw inside the request handler we put together, we are sending
back an array with all of our cell objects inside of it.
So data right there, that should be an array of cell objects.
Let's try to just annotate this thing in that fashion.
I'm going to say that data is.
A cell array.
Now, if I mouseover data, I'm told, yep, that is an array of cells.
Now we can use that data property to dispatch an action that we will do a dispatch.
With a type of action type dot that sells complete.
And our payload in this case.
Will be that data array.
Hey, that looks pretty good now we can just handle the case, we're going to leave the case just really
simple and straightforward here.
So we're just going to dispatch the appropriate action type and we'll just put on whatever message came
across inside the air.
So we'll essentially just do this batch with a type of action type that sells air with a payload of
our message.
If anything goes wrong with, say, our network connection, error message is probably going to be something
like a network request failed.
So it's not a very descriptive error message, but it's good enough right now.
OK, so that looks pretty good for our action creator.
Now, the last thing we have to do is go back over to our cells reducer and make sure that we handle
these three different action types.
Let's take care of that step in just a moment.