how useEffect maintain the state

207 views Asked by At

My questions is conceptual and that is we all know that using useEffect Hook, every time when useEffect calls after every render React cleans up use Effects from the previous render before running the effects next time and declares useEffect again with his new render. How useEffect maintains the previous state?.

1

There are 1 answers

0
Adam Jenkins On

Just google it. In short, react knows which components are mounting, mounted, etc. It keeps track of them all. Because it keeps track of them all, it can assign arbitrary data to each one. This is essentially what hooks are.

All hooks do is essentially provide a mechanism to allow instance variables (some form of internal state, but not "state" like you think in react) for functional components.