overleaf/services/web/frontend/js/shared/hooks/use-is-mounted.ts

15 lines
267 B
TypeScript
Raw Normal View History

import { useLayoutEffect, useRef } from 'react'
export default function useIsMounted() {
const mounted = useRef(false)
useLayoutEffect(() => {
mounted.current = true
return () => {
mounted.current = false
}
}, [mounted])
return mounted
}