degmods.com/src/hooks/useDidMount.ts
2024-07-25 20:05:28 +05:00

13 lines
262 B
TypeScript

import { useRef, useEffect } from 'react'
export const useDidMount = (callback: () => void) => {
const didMount = useRef<boolean>(false)
useEffect(() => {
if (callback && !didMount.current) {
didMount.current = true
callback()
}
})
}