MCPcopy Index your code
hub / github.com/editablejs/editable / useCallbackRef

Function useCallbackRef

packages/ui/src/hooks/use-callback-ref.ts:7–16  ·  view source on GitHub ↗

* A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a * prop or avoid re-executing effects when passed as a dependency

(callback: T | undefined)

Source from the content-addressed store, hash-verified

5 * prop or avoid re-executing effects when passed as a dependency
6 */
7function useCallbackRef<T extends (...args: any[]) => any>(callback: T | undefined): T {
8 const callbackRef = React.useRef(callback)
9
10 React.useEffect(() => {
11 callbackRef.current = callback
12 })
13
14 // https://github.com/facebook/react/issues/19240
15 return React.useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, [])
16}
17
18export { useCallbackRef }

Callers 12

scroll-area.tsxFile · 0.90
useDebounceCallbackFunction · 0.90
useResizeObserverFunction · 0.90
avatar.tsxFile · 0.90
MenuFunction · 0.90
menu.tsxFile · 0.90
MenuSubFunction · 0.90
usePointerDownOutsideFunction · 0.90
useFocusOutsideFunction · 0.90
useEscapeKeydownFunction · 0.90
useControllableStateFunction · 0.90
useUncontrolledStateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected