Nice trick ! Can you tell some use cases because I don't really understand the purpose. If I need to know if a Component is mounted, I look for it in DOM, isn't it ?
There are specific cases when it is necessary to understand whether the component is mounted or not outside the useEffect method, for example, in some functions that can be called in child components before the parent component is mounted. Sometimes it's useful to control 3d party libs initialization. I saw a lot of people use a state to handle such behavior, but it's not a good approach and leads to unnecessary re-render.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice trick ! Can you tell some use cases because I don't really understand the purpose. If I need to know if a Component is mounted, I look for it in DOM, isn't it ?
There are specific cases when it is necessary to understand whether the component is mounted or not outside the
useEffect
method, for example, in some functions that can be called in child components before the parent component is mounted. Sometimes it's useful to control 3d party libs initialization. I saw a lot of people use a state to handle such behavior, but it's not a good approach and leads to unnecessary re-render.