1import {useCallback, useEffect, useRef, useState} from 'react'; 2 3export function useOnMounted() { 4 const onMounted = useRef(false); 5 const [isLoading, setLoading] = useState(true); 6 7 useEffect(() => { 8 onMounted.current = true; 9 setTimeout(() => { 10 setLoading(false); 11 }); 12 13 return () => { 14 onMounted.current = false; 15 }; 16 }, []); 17 18 return {onMounted: useCallback(() => onMounted.current, []), isLoading}; 19} 20