From f1a8e32b1a674c9ee30678be4d93630d4474afa5 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 7 Aug 2026 02:51:09 -0700 Subject: [PATCH 1/2] Align ref helper flow types (#57850) Summary: 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. 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); From 9e3c9c3e3a54457eeb02017f51daedd99aaddd8c Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 7 Aug 2026 02:51:09 -0700 Subject: [PATCH 2/2] Remove accidental ref callback return values (#57849) Summary: Ref callbacks commonly used expression bodies that returned assignment or collection method results. Use block bodies so these callbacks return `void`, matching React's ref contract. Changelog: [Internal] - Make callback refs return `void` explicitly. Differential Revision: D115064073 --- .../js/examples/TextInput/TextInputSharedExamples.js | 4 +++- packages/rn-tester/js/examples/Timer/TimerExample.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js index 3aa30acc36ac..81eac46a8e49 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js @@ -563,7 +563,9 @@ class SelectionExample extends React.Component< onChangeText={value => this.setState({value})} // $FlowFixMe[method-unbinding] added when improving typing for this parameters onSelectionChange={this.onSelectionChange.bind(this)} - ref={textInput => (this._textInput = textInput)} + ref={textInput => { + this._textInput = textInput; + }} selection={this.props.imperative ? undefined : this.state.selection} style={this.props.style} value={this.state.value} diff --git a/packages/rn-tester/js/examples/Timer/TimerExample.js b/packages/rn-tester/js/examples/Timer/TimerExample.js index a80bdbac9f65..d9417d4c33b6 100644 --- a/packages/rn-tester/js/examples/Timer/TimerExample.js +++ b/packages/rn-tester/js/examples/Timer/TimerExample.js @@ -297,7 +297,9 @@ class IntervalExample extends React.Component< return ( (this._timerTester = ref)} + ref={ref => { + this._timerTester = ref; + }} dt={25} type="setInterval" />