mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
18 lines
346 B
TypeScript
18 lines
346 B
TypeScript
|
import { useRef, useEffect } from 'react'
|
||
|
|
||
|
function useMounted({ onMount = () => {}, onUnmount = () => {} } = {}) {
|
||
|
const isMounted = useRef(false)
|
||
|
useEffect(() => {
|
||
|
isMounted.current = true
|
||
|
onMount()
|
||
|
return () => {
|
||
|
isMounted.current = false
|
||
|
onUnmount()
|
||
|
}
|
||
|
}, [])
|
||
|
|
||
|
return isMounted
|
||
|
}
|
||
|
|
||
|
export default useMounted
|