Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
useEffectOnce exit is not going to fire as far as I can see. This hook works to defeat the hook being called twice, but the cleanup functions will never get called as far as I can see.
I honestly don't know how to fix this. I've been trying everything I can think of.
I help people develop software and test things better. Find me at EvilTester.com I also help people market their software and write about marketing over on Talotics.com
I help people develop software and test things better. Find me at EvilTester.com I also help people market their software and write about marketing over on Talotics.com
Probably just a minor copy/paste bug, but there is an extra open parenthesis here that doesn't have a matching close below.
I am also seeing a problem when Strict mode is not enabled or app is build in production mode, the unmount event will not fire.
Here's my code for testing:
Output in production mode when mounting and unmounting the component once.
useEffectOnce exit
was expected to fire here.useEffectOnce exit
is not going to fire as far as I can see. This hook works to defeat the hook being called twice, but the cleanup functions will never get called as far as I can see.I honestly don't know how to fix this. I've been trying everything I can think of.
Thanks for pointing this out Jack. Niall updated the code, hopefully it is better.
Thanks, we've updated the code to fix typos and hopefully addressed Jack's point below.
What is the difference between development and production hook behavior? Could you please explain.
more info here: React 18 — the trickiness of useEffect