Returns a callback function that returns a boolean
when called indicating if the current component is still mounted. This is useful for gatekeeping code paths that would set local component state after asynchronous behavior.
const [state, setState] = useState();
const isMounted = useIsMounted();
useEffect(() => {
someAsyncThing().then(() => {
if (isMounted()) {
setState(/* ... */);
}
});
}, [/* effect dependencies */]);