degmods.com/src/hooks/useDidMount.ts

13 lines
262 B
TypeScript
Raw Normal View History

2024-07-25 15:05:28 +00:00
import { useRef, useEffect } from 'react'
export const useDidMount = (callback: () => void) => {
const didMount = useRef<boolean>(false)
useEffect(() => {
if (callback && !didMount.current) {
didMount.current = true
callback()
}
})
}