You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
@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.
useEffectAfterMount
does not in React 18's strict mode in development environment, because react first mounts component, which setsisMounted.current
totrue
, then unmounts component and mounts again. The problem is thatisMounted.current
is true on second mount.Solution - reset
isMounted.current
on unmount.The text was updated successfully, but these errors were encountered: