wix-style-react
Version:
18 lines (15 loc) • 481 B
JavaScript
import { useRef, useEffect } from 'react'; // Returns a function that checks whether component is still mounted
var useIsMounted = function useIsMounted() {
var mountedRef = useRef(true);
useEffect(function () {
// React performs the cleanup when the component unmounts
var cleanup = function cleanup() {
mountedRef.current = false;
};
return cleanup;
}, []);
return function () {
return mountedRef.current;
};
};
export default useIsMounted;