DEV Community

Discussion on: Why Effects shouldn't lie about their dependencies

Collapse
 
aman_singh profile image
Amandeep Singh • Edited

Hi,
In your code snippet, you are setting alternate key (true and false) on every click handler to the div element. key plays an important role in React reconciliation process. Setting a different key on your div element is like asking React to recreate the whole tree, which follows the process of unmounting the component and remounting it. And doing so, it runs the cleanup effect as it will do in the normal umount cycle.
Hope it helps 🙂

Collapse
 
dance2die profile image
Sung M. Kim

Thanks Amandeep for the explanation, links (and the nice word highlights) 😀

Thread Thread
 
aman_singh profile image
Amandeep Singh

Thanks Sung. Happy that it was helpful. 😀