Though this does a job, but it's still a workaround. I think the preferable way is to try to clean-up any side-effects when component is unmounted. In your example, setTimeout function actually returns timeout id, that you could use to do clearTimeout(timeoutId) on component unmount.
Yeah agreed, but the real deal is that we have a method to check if a component is unmounted, we can use it anywhere we feel the need to have this functionality.
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.
Though this does a job, but it's still a workaround. I think the preferable way is to try to clean-up any side-effects when component is unmounted. In your example,
setTimeout
function actually returns timeout id, that you could use to doclearTimeout(timeoutId)
on component unmount.Yeah agreed, but the real deal is that we have a method to check if a component is unmounted, we can use it anywhere we feel the need to have this functionality.