MCPcopy
hub / github.com/bvaughn/react-window / useStableCallback

Function useStableCallback

lib/hooks/useStableCallback.ts:5–19  ·  view source on GitHub ↗
(
  fn: (args: Args) => Return
)

Source from the content-addressed store, hash-verified

3
4// Forked from useEventCallback (usehooks-ts)
5export function useStableCallback<Args, Return>(
6 fn: (args: Args) => Return
7): (args: Args) => Return {
8 const ref = useRef<typeof fn>(() => {
9 throw new Error("Cannot call during render.");
10 });
11
12 useIsomorphicLayoutEffect(() => {
13 ref.current = fn;
14 }, [fn]);
15
16 return useCallback((args: Args) => ref.current?.(args), [ref]) as (
17 args: Args
18 ) => Return;
19}

Callers 3

useDynamicRowHeightFunction · 0.90
useVirtualizerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…