From 88820254e59b11deb5216fdb5a9e026f6979d670 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 17 Aug 2026 08:43:33 -0700 Subject: [PATCH] Align ref helper flow types (#57850) Summary: Pull Request resolved: https://github.com/react/react-native/pull/57850 React ref callbacks may return only `void` or a cleanup function. Align `TRefCallbackFor` and the related shared callback-ref helpers directly with the core Flow React ref types, then update consumers whose callbacks returned incompatible values. This keeps the contracts canonical and avoids introducing a parallel restricted variant. Changelog: [Internal] - Align ref helper types with the React callback contract. Reviewed By: SamChou19815 Differential Revision: D115064072 fbshipit-source-id: b308ac2b9a453b494c64bdf3d37873b69040ce4c --- 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 8f9ed0b3842..e1e38a0dd7a 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 0e930cdae4a..b6dcef3bd32 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);