stacker.news/components/use-no-initial-effect.js

14 lines
265 B
JavaScript
Raw Normal View History

2023-10-06 20:01:51 +00:00
import { useEffect, useRef } from 'react'
export default function useNoInitialEffect (func, deps) {
const didMount = useRef(false)
useEffect(() => {
if (didMount.current) {
return func()
} else {
didMount.current = true
}
}, deps)
}