In this video we're going to start working on a second way of solving our overstretching issue.
So minimalizing definitely worked pretty well.
But like I said the downside is that we now can now call this action Creator only one time with each
unique user ID and that effectively means that we can only fetch each user one time inside of application.
Now it's incredibly likely that you will eventually work on an application where you are going to want
to re fetch different resources over time.
So this video we're going to take a look at a different way of solving this over fetching problem.
Now the second way that we're going to solve this is going to be a little bit more obvious in nature.
So here's the idea.
We're going to create a new action creator called fecche posts and users and that's going to do exactly
what you would think.
There's just one little twist to it.
So when ever we call fecche posts end users this is the logic that we're going to execute.
We're going to first call fecche posts.
We're then going to get a list of all of our posts from that list of posts.
We'll find all of our unique user IDs.
We will then iterate over all those unique user IDs.
And then finally we're going to call that user which with each of those now just a second ago I mentioned
that there is a little twist here and the twist is that we are not going to replace the fecche posts
action creator and the fetch user action creator.
So in other words fecche posts end users is not going to have some logic inside of it to make a network
request over to our API.
Instead we're going to keep all that network because logic inside of our two existing action creators
fetch posts and fetch user.
The idea here is that when you start working on your own projects you want to create action creators
that are a small and compact as possible.
Just think about it.
If we made an application and the only action creator inside of it was fecche posts and users then maybe
for our app as it stands right now we would be in a pretty good spot.
But maybe at some point in time in the future we would want to put together some like maybe user profile
page and in time that the user went to that profile page we would want to show details about some very
particular user.
In that case we would want to have an action creator that fetch just one user so we can get details
about that particular user and show them on the screen.
So when you start putting together these kind of big combo action creators that do multiple things.
A very good approach is to first create some action creators that do very small things and essentially
kind of wired them altogether into the more mega action creator so to speak that does everything for
you.
OK so with that in mind because we are going to reuse these action creators it's going to make life
just a little bit challenging.
But I'm very confident that you'll understand exactly what is going on.
All right so we're going to flip back over to our code editor I'm still inside of my action creators
file.
The first thing we're going to do is refactor our Fettes user action creator back to its previous state.
So back to the pre memorized version of it.
Now before we do that refactor I'm going to copy it down underneath itself and I'll comment out that
copy right there.
So the reason we're making a little uncommented version right there is just you have a reference of
the memorized version of this approach.
So we're not going to refactor fetch user back into the non memorized version.
This will be a pretty easy refactor.
You can either hit undo a whole bunch or we can just do the re factor together right now.
Honestly it won't be that bad.
It's the first 10 going to do to return this to its previous state is going to be to remove the entire
line that says Konst underscore Fettes user.
So I'm going to delete all that.
Next up I'm going to remove everything from the semi-colon right here all the way to underscore Fettes
user and I will replace it with a curly brace like so.
I will then mark the inner function that we return right here.
As async And then finally I'm going to delete the closing parentheses at the very end.
And that's it.
So now we should be able to save this and then flip back over to application and not see any error messages
or anything like that.
So I am back here.
I do not see any error messages.
If you see an error message that means that you made a little typo during the refactor and you'll want
to fix that up really quickly.
Now you'll notice that because we are now working with the non minimalized version of our action creator
we're back to our original state where we are making a ton of requests.
All right let's take a quick pause right here.
When we come back the next section we're going to start creating the fecche posts and users action creator.