Languages
[Edit]
EN

React - is component mounted hook

5 points
Created by:
Remy-Lebe
832

In this short article, we would like to show how to create React hook that stores information about component is mount or removed.

Quick solution:

Note: the main advantage of the solution is the possibility to access the current state in different places with React reference (by accessing mountedRef.current).

 

Practical example

Edit

In this section we present an example where the programmer is able to check if the component is still mounted after some async operation - it let to decide if we can set a new state for some hook inside the component.

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join