3 ms·
and what happens if I unmount and remount it? something like: <div> {isLoggedIn ? <LogoutButton /> : abcd } </div> and I change the value of isLoggedIn. Does
by sydd 6y ago
and what happens if I unmount and remount it? something like:
<div>
{isLoggedIn ? <LogoutButton /> : abcd }
</div>
and I change the value of isLoggedIn. Does the state reset? I'm not asking for a solution, just pointing out that even a 'simple' hook like useState has its small quirks.
- acemarke 6y agoIt does reset, because toggling that flag will unmount the old instance of the component, and then mount a new instance. This is the same behavior as has always existed with class components and `this.setState()`. Component-scoped state only exists as long as that specific instance of the component is mounted.