In the last video we spoke about exactly how we're going to load up our users into our application.
So we're not going to take the easy way out.
We're going to do things the more realistic albeit a little bit more challenging way.
And like I said I can tell you right now we are going to run into one or two issues.
So if at some point something looks a little bit off don't sweat it we're probably going to end up fixing
it.
All right.
So here's the idea.
We're going to create a new action creator called fetch user.
Now remember our current action creator is called fetch posts and there's that s on the end which indicates
we are fetching multiple posts from one action Creator.
This new action creators called fetch user singular and so the idea here is that we're going to use
the action creator to fetch one individual user at a time.
Now the action crater itself it's going to make a request over to that API.
It's going to get our chosen user like some user with some particular ID and then it will dispatch an
action with the type of something like fecche user and will have our data on the pallet property.
Remember we don't really want to use just the response that I typed on here it's actually response data
that we care about.
So then we're going to also create a user's reducer which is going to hold a list of all of the users
we have into our application.
So notice how the action creator is fetching one record.
But we're going to essentially tabulate or collect all the different records that we get inside of that
reducer.
OK.
Let's get to it.
I'm going to flip back over to my code editor.
We're going to first start off inside of our actions index indexed Yes file by putting together a new
action creator to fetch just one user at a time.
So the actual creator we're going to put together is going to initially look basically identical to
the one that we have right here.
So I'm going to say export Konst fetch user when we call this action creator we're going to pass in
the idea of the user that we want to fetch as an argument.
So this idea right here this is going to be the idea of the user that we want to fetch.
So then we're going to use the same format where we have a function that returns a function.
So I will say async dispatch
and then we'll say Konst response is going to be a wait.
Jason plays older.
Don't get in now this time we are not going to make a request to the posts and point.
Instead we want to make requests to the users and point but we want to fetch a user with this very particular
ID.
And remember as I showed you in the last video we can fetch one individual user at a time by putting
a slash and then the idea of the user that we want to fetch.
So over here we're not going to put just users of what we really want is users slash.
Id like so we're going to rewrite that using yes 20:15 syntax with a template string instead.
Just to kind of clean up a little bit.
So I'm going to replace the single quotes with back ticks like so and I'll put my dollar sign curly
braces ID inside there.
All right so after we make that request and get back a response I'll then dispatch an action with type
batch underscore user.
And again remember it is singular.
No æsir because we are fetching one user at a time and then on our Paillard property we will put response
dot data.
All right so that's pretty much it.
Now one thing I want to point out here is that in fetch posts where we fetch a list of posts the response
that we got was a array of records.
So notice how.
Here's the Post's end point we got back an array of objects but when we fetch one user at a time we
don't get an array we get just an object that has details about that given user.
So just something I want to point out because that's going to end up in are reduced to looking like
ever so slightly different.
Maybe we will see.
OK.
So this looks good.
We've got our action creator put together.
So let's take a quick pause right here.
When we come back in the next section we're going to start putting together our user Hetter component
and making sure that it can call Fettes user right here at the appropriate time.
So a quick pause and I'll see you in just a minute.