We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
cb
useOnUnmount
1 parent 5cfbb4b commit 74c9873Copy full SHA for 74c9873
packages/@headlessui-react/src/hooks/use-on-unmount.ts
@@ -1,7 +1,10 @@
1
import { useRef, useEffect } from 'react'
2
import { microTask } from '../utils/micro-task'
3
+import { useEvent } from './use-event'
4
5
export function useOnUnmount(cb: () => void) {
6
+ let stableCb = useEvent(cb)
7
+
8
let trulyUnmounted = useRef(false)
9
useEffect(() => {
10
trulyUnmounted.current = false
@@ -11,8 +14,8 @@ export function useOnUnmount(cb: () => void) {
11
14
microTask(() => {
12
15
if (!trulyUnmounted.current) return
13
16
- cb()
17
+ stableCb()
18
})
19
}
- }, [])
20
+ }, [stableCb])
21
0 commit comments