mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 04:58:46 -05:00
3c01402bbd
PDF Detach v2 GitOrigin-RevId: 3deb76474185f9176cde23ab32ef51b90df6e8e9
21 lines
519 B
JavaScript
21 lines
519 B
JavaScript
import { useCallback, useRef } from 'react'
|
|
|
|
export default function useCallbackHandlers() {
|
|
const handlersRef = useRef(new Set())
|
|
|
|
const addHandler = useCallback(handler => {
|
|
handlersRef.current.add(handler)
|
|
}, [])
|
|
|
|
const deleteHandler = useCallback(handler => {
|
|
handlersRef.current.delete(handler)
|
|
}, [])
|
|
|
|
const callHandlers = useCallback((...args) => {
|
|
for (const handler of handlersRef.current) {
|
|
handler(...args)
|
|
}
|
|
}, [])
|
|
|
|
return { addHandler, deleteHandler, callHandlers }
|
|
}
|