From daa4631f387c1306847e00630d1f6c72ac39a951 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 6 Aug 2026 11:53:31 -0700 Subject: [PATCH] Restrict ref helper return types Summary: React ref callbacks may return only `void` or a cleanup function. Align shared callback-ref contracts with that behavior so consumers cannot hide incompatible returns behind `unknown`. Changelog: [Internal] - Align ref helper types with React's callback contract. Differential Revision: D115064072 --- packages/react-native/Libraries/Utilities/useRefEffect.js | 4 +--- .../src/private/animated/createAnimatedPropsHook.js | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/react-native/Libraries/Utilities/useRefEffect.js b/packages/react-native/Libraries/Utilities/useRefEffect.js index 8f9ed0b3842d..e1e38a0dd7ac 100644 --- a/packages/react-native/Libraries/Utilities/useRefEffect.js +++ b/packages/react-native/Libraries/Utilities/useRefEffect.js @@ -10,8 +10,6 @@ import {useCallback, useRef} from 'react'; -type CallbackRef = T => unknown; - /** * Constructs a callback ref that provides similar semantics as `useEffect`. The * supplied `effect` callback will be called with non-null component instances. @@ -28,7 +26,7 @@ type CallbackRef = T => unknown; */ export default function useRefEffect( effect: TInstance => (() => void) | void, -): CallbackRef { +): React.RefCallback { const cleanupRef = useRef<(() => void) | void>(undefined); return useCallback( (instance: null | TInstance) => { diff --git a/packages/react-native/src/private/animated/createAnimatedPropsHook.js b/packages/react-native/src/private/animated/createAnimatedPropsHook.js index 0e930cdae4a0..b6dcef3bd329 100644 --- a/packages/react-native/src/private/animated/createAnimatedPropsHook.js +++ b/packages/react-native/src/private/animated/createAnimatedPropsHook.js @@ -35,11 +35,10 @@ type ReducedProps = { collapsable: boolean, ... }; -type CallbackRef = T => unknown; export type AnimatedPropsHook = ( props: TProps, -) => [ReducedProps, CallbackRef]; +) => [ReducedProps, React.RefCallback]; type UpdateCallback = () => void; @@ -55,7 +54,7 @@ export default function createAnimatedPropsHook( return function useAnimatedProps( props: TProps, - ): [ReducedProps, CallbackRef] { + ): [ReducedProps, React.RefCallback] { const [, scheduleUpdate] = useReducer(count => count + 1, 0); const onUpdateRef = useRef(null); const timerRef = useRef(null);