MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useSyncRef

Function useSyncRef

packages/react-aria/src/utils/useSyncRef.ts:22–36  ·  view source on GitHub ↗
(context?: ContextValue<T> | null, ref?: RefObject<T | null>)

Source from the content-addressed store, hash-verified

20
21// Syncs ref from context with ref passed to hook
22export function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>): void {
23 // oxlint-disable-next-line react/react-compiler
24 useLayoutEffect(() => {
25 if (context && context.ref && ref) {
26 // oxlint-disable-next-line react/react-compiler
27 context.ref.current = ref.current;
28 return () => {
29 if (context.ref) {
30 // oxlint-disable-next-line react-hooks/exhaustive-deps
31 context.ref.current = null;
32 }
33 };
34 }
35 });
36}

Callers 4

PressResponder.tsxFile · 0.90
usePressResponderContextFunction · 0.90
useFocusableContextFunction · 0.90
Menu.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected