Now we're in good shape and we're almost done, but there are two gotchas in our current application,
so everything works fine.
We check for the query.
We know that if we're getting back to query, then of course, we have the object and then the array
is in the data object and the name is the result.
However, if we're just getting default photos, then of course we separate out the old photos and then
we add that data.
So I think I can remove the console plug and I'll show you both of the gotchas.
So the first gotcha is if we type here cat and if we search for it, technically our functionality works.
But notice how we're not changing those default ones.
So if we do it over here, yeah, I'm getting this right and I can clear notice that I'm getting more
items right now, but I'm not wiping out the old ones.
And what I would want instead is that when we type something instead of just upending them to our country,
because notice now, of course, we have 90, I would want instead wipe out the old ones.
So, yes, we'll still use this functionality when it comes to query.
But then if the page is number one, so if I know that I'm typing a brand new query, then I also don't
want to wipe out the old values.
So we'll scroll down here and we'll add one more.
If so, say if I'm on query and the page is equal to one, then we'll wipe out the old values.
So if page is equal to one, then instead of upending to our country where we're going to do that or
say return and remember whatever, we're returning and we'll just say data results.
Now, of course, in this case, this is going to become else F, of course.
So that's why it will say here else.
If so, if the query, then of course everything is going to be exactly the same.
Now, one thing over here is going to be the simple fact that it's going to work or here with the dog.
And yeah, we get the results.
But what do you think happens when we start scrolling?
And again, I'm going to do that on a bigger screen because what I want you to see how the values change
are going to go.
Dog, we're getting dog photos online.
Let me refresh.
For some reason, I don't see the components now.
I do.
And notice how the value is changing for the pages.
So now we have, of course, page five three and then we keep on scrolling, keep on scrolling and keep
on changing this value.
So now of course, when we type well, it's not going to be equal to one.
Correct.
So when I have a new query of QUAT, then again I'm appending to my current one.
And that's not what I would want in here.
If I scroll down and notice where we're fetching images instead, I would want to set page two one.
Correct.
So we're going to go set page and set it equal to one and two things are happening.
First of all, we are resetting the page value.
And the second thing is we technically even don't need to call such images because we already have a
user that is listening for the page.
So that should work.
But then there's one last gotcha.
So let me save this one and let's just type over here, dog, and then we're going to keep on scrolling
and technically we'll get dark photos.
But notice how normally we didn't wipe out the old values.
So that was the issue.
So why do you think that is happening now?
Because if I refresh.
And if I start typing from the scratch and dog, check it out, once I submit the form, the value is
already one, so I'm getting already page number one.
So that's why nothing is happening and we simply need to fix it.
If we scroll up and check out the page.
I'll get the default one to be zero.
So now my functionality will still work where once I submit McQuary, I'll always set my page to be
equal to one correct.
But my default one is zero, meaning there's going to be a re render.
So now let's start out by default.
I'm getting these images with page zero.
But then if I typed the dog now set my page equal to one, so I'll wipe out the old values and then
everything works as I keep on scrolling, I'm going to be getting my dog images.
So of course my pages will be changing and so will be the new fetch request.
That was the project.
I understand that this was somewhat big, but like I warned you in the beginning of the section, these
are advanced projects.
Of course, there's going to be a lot of moving pieces.
Hopefully everyone enjoyed the project and I hope to see the next one.