So next, what we'll do is we'll create another like like an array using the used to talk.
Before that, we'll write, contest and copy that the name of that particular area would be cocktails,
and that will be like creating using their used data.
So cocktails is the variable like right now.
It's not specified who what it is, but the specification is done over here and we provide the initial
value.
And here, for example, in this, we have provided tools.
So that means it's a Boolean and we are provided a string.
So that means it is a it is a string.
So that is what we are doing here.
Next, we will write the function to set cocktails.
And this would be equal to you with the state.
Users state and inside this will ride the initial value to it, so the initial value is an empty at
a now whatever we specify here, that is the particular data type of this variable.
So here I have a specified and empty array.
So that means this is an empty array and that has no value inside this right now.
Or you can provide a semicolon here if you want, or you can leave it as it is.
I will do it like this for the sake of the convention.
And now we will make use of this particular A..
So when we go down, so after this return?
What we will do is we will get rid of all of the late night tubes and things, so let me just provide
semicolons and let me set up the.
Conventional so often we are done with this, but it done for this complete if block, like whenever
this is executed, it will return a particular.
OK, so we have done all, we have returned all of this and once this is done.
OK.
So inside this, only like after all of this is done, they're done, is done.
And this mapping is done.
So after the mapping is done, what we'll do is we'll set the to new deals.
Now what is the new Google new cocktail?
Is this particular one strand which we have created or Will said that said, it's not an uppercase that.
What?
Basically, this function that via via just calling this function.
OK, well, that will be.
That cockatiels and inside this will pass of like an argument, and that argument will be the value
to this variable, whether it is a tree or a string or a Boolean, whatever it is.
So here what we'll do is we'll pass the new cocktails we'll write in the new year.
Then we'll provide a semicolon.
Now what this does is that Ben discovered this piece of code is executed so that the control comes over
here and this function is called and the argument is parsed inside this and the whatever is the value
of that argument.
So that becomes the value of this cocktail variable.
OK, so that is what we have done.
OK.
Next, we'll write the L spot.
So far, we have only written if by not if this is correct.
If this the condition is true, this will execute.
But what if the condition is not true?
So for that, we'll write the L'ESPOIR rule.
Here we go.
After like wherever this f is ending, we'll provide an alt block.
Well, else at this.
I like tech cocktails.
Expect cocktails.
And then I'll pass an empty area like if we have not received any data, so what?
We are going to read nothing and empty a simple, empty area.
So that is what we have done.
And whenever we are searching for something and we don't get, we don't get anything.
And the length of the result is like it's like zero like less than one.
So that means we have not they have not got the desired results.
So we'll just display that, nor does are found on all my time next.
What will do is all of when all of this is done, well, that means we have have the data or we have
at least grab that response, whether it is our data or whether it is an empty array.
After all, this is done, Will said, downloading two files.
So after this?
Bill, right.
Let me check whether things are ending, and I try only inside the if and it's and basically after the
ends, we'll ride this, that lauding.
So what we're doing and we'll pass all that, Mr. Data has been grabbed.
Now you can just take rest and you can be like, say, two faults.
So.
And now we'll ride the catch block.
Right now, we have just returned the tribe block and now we'll ride the cats block, like if what if
things go didn't go according to us and we we're an error, and that is a problem too.
That needs to be displayed using that gas that it will cause the error.
OK, so that is a side loading here, and it is set to false.
And after that from here, let me see Batista try getting over here.
I is getting over here.
So from here, will Randy catch block?
So throw me in right catch.
And so that will be.
An argument that doesn't add up.
And now in saying this is biased.
Like we like, right, whatever we need to do once it has been resolved, so we will right console,
like will console better console not log better will ride the better, it won't sweat enough.
Next, what we'll do is we'll send the loading to Salt Lake.
OK, stop the data.
That is an error, so don't need to display the loading video, so we'll start alluding to false.
And next, what we'll do is we look like this is this was it for.
All of this.
But now we want to write some like it was effect function to whenever the search term changes.
All of this needs to be like rendered and all of that function needs to be fired off or that we need
to do so after the catch is over.
OK, let me see where Kate is getting over after the catch is getting all word.
So because this all is happening inside the U.S callback, OK, so inside the U.S callback, OK, we
also give an like an dependency.
Or we can just see an I.D. so that this all thing is dependent on the search term, basically.
So we will.
We'll provide that inside this dependency on for.
After this is done or it and and we will give a command and we'll give our dependency to the dependency
area, will will ride the variable on which all of the function is taking place or all all of the water
will be returned.
So that is dependent on a particular variable.
With that particular variable will be the star system.
But.
Don't.
And.
OK.
So this is the variable for on which everything is dependent.
So next will be writing a you a state like whenever we change, whenever we change that.
Like when we type in that input box.
OK, so there would be a variable that will be storing that variable like whatever we input, whatever
the input, we are typing that variable as this search term.
Now on what every execution is dependent, this particular variable that is the system.
We'll make another use a fact hook and insert that they use effect.
We'll call all of this function.
Would that function, this all function will be executed only when this particular dome changes, so
for that, we'll be using the use effect.
OK, well, let me first import OK, I've already imported that.
And now let us use it inside our core.
So after we are done with this, so it's done.
Let me provide a semicolon here and after we have done here who all we will provide.
They use affect talk.
So let me not get stuck in here to what we'll do is we'll do it, use effect and use effect expects
a function basically if we don't know and if you don't know about you as vote, you can just google
it.
It's a really, really important talk if you're working with React.
So inside this, what is the function that needs to be executed on the change of that particular variable?
Now.
We have only created one function so far, and that is this that is this.
Better drinks.
So that is the only function that needs to be called.
We don't have anything else.
So we'll provide that inside the EU as a federal civil rights fetch.
Name of the function, basically.
Brings.
And.
We'll provide this.
So this is the function which will be called then.
Now here you should ask a question to yourself then when this function will be called, what is the
condition for calling this particular function?
So then you will provide the variable to this dependency.
Now, if this is left blank, that means this function would be called only once when the pages loaded.
So here you will write.
A variable name that is the search term and activity which is responsible for the execution of this
particular function is fetching drinks.
Rich drinks.
Oh, I'll provide a summary gotten here and.
That's it, basically.
Now what we'll do is we'll return the provider and we'll move further with the global welcome texting
too.
That will do in the next video.