overleaf/services/web/frontend/js/shared/hooks/use-is-mounted.js
Alf Eaton ec3400c7cd Add useIsMounted hook (#4039)
GitOrigin-RevId: 4ece1381fbfbed048fe46a399a60e9aab2f3526e
2021-05-19 02:06:31 +00:00

13 lines
235 B
JavaScript

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