Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hooks] useEffectAfterMount does not in React 18's strict mode in development environment #25

Open
ArtemGolovko opened this issue Dec 23, 2022 · 2 comments

Comments

@ArtemGolovko
Copy link

useEffectAfterMount does not in React 18's strict mode in development environment, because react first mounts component, which sets isMounted.current to true, then unmounts component and mounts again. The problem is that isMounted.current is true on second mount.

Solution - reset isMounted.current on unmount.

@heyitsarpit
Copy link
Owner

@ArtemGolovko
The fact that react 18 strict mode behaviour breaks this hook makes me think that this hook shouldn't even exist. It's a hack to begin with since I created this to deal with next/router having undefined data query params on first render.

Having isMounted false after unmount may cause other issues. useEffect's clean-up runs after the next render, before the next useEffect. This means it will be reset to false on every render. causing the effect to never execute.

@heyitsarpit
Copy link
Owner

heyitsarpit commented Jan 12, 2023

I will be marking this hook as deprecated for the next release and remove it later on a major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants