SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Function useCallbackRef

    • A callback with a stable identity that always runs the latest closure — like useCallback, except that a change in deps does NOT change the returned function. Pass it to memoized children, effect dependency lists or long-lived subscriptions (a command contribution's data, a model listener) without re-running them whenever the closure's inputs change.

      This is the "latest ref" pattern (React's useEvent RFC; ahooks' useMemoizedFn; Radix's useCallbackRef).

      Usage notes:

      • List every value the callback reads in deps. The closure is only refreshed when deps change, so a missing dependency means the stable function calls a stale closure.
      • Call it from events and deferred work, not during render. Its identity never changes, so a component that reads its result while rendering is not re-rendered when the inputs change.
      • For logic called only from an effect, React's own useEffectEvent (React 19.2+) is the standard alternative. It cannot be passed to children or called during render, which this hook allows.

      Type Parameters

      • T extends (...args: any[]) => any

      Parameters

      • callback: T | null | undefined

        The function to wrap; null/undefined yields a function returning undefined.

      • deps: DependencyList

        Every value callback closes over.

      Returns T