简体   繁体   中英

how useEffect maintain the state

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? .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM