react-use/docs/useRefMounted.md
2018-12-05 15:23:43 +01:00

26 lines
404 B
Markdown

# `useRefMounted`
Lifecycle hook that tracks if component is mounted. Returns a ref, which has a
boolean `.current` property.
## Usage
```jsx
import {useRefMounted} from 'react-use';
const Demo = () => {
const refMounted = useRefMounted();
useEffect(() => {
setTimeout(() => {
if (refMounted.currrent) {
// ...
} else {
// ...
}
}, 1000);
});
};
```