mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
- it has more obvious name; - returns a function that check mount state -> more handy ti use due to less to write; - has tests;
484 B
484 B
useMountedState
Lifecycle hook providing ability to check component's mount state.
Gives a function that will return true if component mounted and false otherwise.
Usage
import * as React from 'react';
import {useMountedState} from 'react-use';
const Demo = () => {
const isMounted = useMountedState();
React.useEffect(() => {
setTimeout(() => {
if (isMounted()) {
// ...
} else {
// ...
}
}, 1000);
});
};