And the last thing that I would want to showcase, just like I promised, there's another use case for
use called back, and that is essentially when we're fetching data.
And an awesome example is over here.
If we check the terminal, we can see that I have this morning where react use of fact has a missing
dependency get product either included or removed from dependency.
Right.
And of course, that is, in my custom, the use feature.
So let's say we'll navigate over there.
We have our custom hooks and then we have our use, which and I can see that the react is complaining
that, hey, listen.
You have got product function over here, so you need to add it as dependency, but before you jump
over it and add it as a dependency, let me warn you that you will create infinite loop y.
Well, let's see.
We have get products.
Correct.
And what is this get products doing.
Well it is calling set products so it sets the stage value which triggers the array render.
So if Al Gore here and you falsey get product is my dependency the first time I'll call the get product,
I'll change that value.
And then since this needs to rerun every time, of course, when we change something about this value
well, since get products once we added there, since it will get created from the scratch once we render,
that's why it will create a infinite loop, because again, the same scenario like we had or here with
index where we have the add to cart each and every time you render you create that function from scratch.
So if this gets added to dependency.
Right, technically each and every time when it gets created from scratch, well, you will render the
component.
Now in function, though, you'll also change the state value.
So you'll have that infinite loop.
And what is the solution?
Well, remember, we have our used callback, right?
So we can go here with use callback and then I can set it equal.
I can say use.
Knock over here what?
So let me wrap everything and now I need to say, well, one, I would want to create that function.
Of course, the answer is when I have a you are all changed.
So once the real change changes, yeah, please recreate that function from the scratch.
And of course, once we have this setup, I can bravely go to use fact and just add my get products
like me.
Reemphasize the point where previously before we added this huge callback, if we simply would add this
product, we would get a infinite loop.
Why?
Because of this would get created each and every time.
Now we only create a new function once the euro changes.
And of course, as a result, we're not getting this infinite loop.
So that would be another use case for use callback hoc.