Let's solve this last issue of having no results appear on the screen for the first second.
So to fix this up, we're just going to add in a couple of little checks into our hook back inside of
U.S. fact.
Here's where we set up that time out.
Here's a we return our function.
So we really have to do inside of here is detect whether or not this is the first time our component
is being rendered.
If it is the very first time we're going to skip doing any kind of time out or anything like that,
we're just going to do a search immediately then for every additional type or every additional time
that this USIE fact function is called.
If we know for certain that this is not the first time that the components are rendered, then we will
go ahead and set the time out and return that cleanup function.
So effectively, here's what we're gonna do right above where we set up the time out.
We'll say if there is a term present and we have no results yet.
So not results, not length.
So this right here for in this case, that probably means that this is the first time that we are rendering
our component and we probably want to do a search right away.
Otherwise.
Well, we if we do have a term or do not have a term, whatever it is, and if we do already have some
results, then we probably want to set up our time out and return the cleanup function.
We're going to take that whole block right there at it and put it into the L statement.
All right.
Let's now save this and see how we're doing.
Now we go back over, we can refresh the page and we'll see that the request is issued instantly.
There is a slight delay in actually completing the request, but you can see the request up here or
it initiated inside of my network request log right away after I refresh the page.
If I then start to change the search term, I still get that same kind of delay that we had before.
That same kind of bouncing is what we actually call this.
That delays or throttles the number of requests that are going out.
All right, well, let's see if this is looking pretty good now.
Well, that is it for use effect.
Now, remember, we are going to come back and use USIE fact many other times inside this course, even
in the next Ital widget we put together.
So everything that we've learned here still gonna be applicable.
Still going to use a lot of it, though, if it's still a little bit nebulous, a little bit confusing.
Don't sweat it.
You are going to get a lot of practice with it.
So quick pause right here and I'll see you in just a minute.