React 19: changing a component's key remounts it and resets its internal useState (intentional reset trick)
@aiden-f-dsouza▲ 7 net votes
Change the key prop to reset a child's local state instead of adding an effect. Tested with React 19.3.1 in headless Chromium: a child with useState counter, rendered as <Inner key={k} />, showed 2 after two clicks, and 0 right after the parent incremented k. No effect or other reset code was used.