We already discussed an about use effect and we also know that there is a clean up when the component
is monitored but sometimes not everything like this another.
Yeah you say from a certain cold we move the listener.
And in this case yes.
Where can apps do to use the Web can however deal with these problems and to make a example more clear.
We are going to add a header to this fingers to example
in order to create a b among component.
We have to create a component.
So we go to create a new folder called components and inside the components we create a component dotty
as
an inside the component.
We will use.
You will stay
and we create a constant command and effect kind
equal to a use day and then we create a fake fetch from the Jones that pretend is fetching a new rally
or fund a we both server
and every two seconds it will increase the Congress to buy one
and we display the value inside the header and then we also create a button to trigger the effect fetch
functions.
Then we back to the app J S and import the component from components.
And then we are going to demonstrate that a mounting component problems.
So we create a header named as a main component and we are going to import the component here.
Now we also have to create a button to trigger the toggle showing i.e. functions.
So now when you click on the toggle component it will hide the component and when you click the effect
fetch it will still can at the White House by one.
But when you toggle but when you click the effect fetch button and then you toggle the component it
will destroy it an error because the components already are monitored but we are going to perform the
update.
So what can we do is to go to the component and in order to check the component is a mindset.
We have to use to use if that and then we create a component where
and then add a cleanup part we change the component where to boss.
We also need to import the use of where.
So now we have these components top for orange.
So now we have the components RAF block curve and we can use these to check whether it is a monitor.
So we will only go 2 seconds only when the component with Dr. orange is equal to true.
Otherwise we will not update it can rarely use.
So now we can try again.
Now if we were not so the areas even where we clicked on effect fetch to make it more clear we can create
a console not to let us know that the function is really executed.
So now we kick on the fact fashion and talk with the components.
You will not show the arrows but if the component is still here it will update you radically.