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

Function useSyncRef

packages/react-aria/src/utils/useSyncRef.ts:22–34  ·  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 useLayoutEffect(() => {
24 if (context && context.ref && ref) {
25 context.ref.current = ref.current;
26 return () => {
27 if (context.ref) {
28 // oxlint-disable-next-line react-hooks/exhaustive-deps
29 context.ref.current = null;
30 }
31 };
32 }
33 });
34}

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