From ba86a8f8632c07bd4bd63cd60fe5099609885e62 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Thu, 15 May 2025 13:59:31 -0700 Subject: [PATCH] Make use of ref-as-prop support in ScrollView (#51365) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51365 Make use of the React 19 feature so that we can remove the remaining `forwardRef` in react native. Changelog: [Internal] Reviewed By: yungsters Differential Revision: D74814123 fbshipit-source-id: 5f9410df1710f6a9c59fea7ce1f225b04b67d664 --- .../Libraries/Components/ScrollView/ScrollView.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js index 95754d5cd36..e7fa9918a6b 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js @@ -1910,23 +1910,25 @@ function createRefForwarder( return state; } -// TODO: After upgrading to React 19, remove `forwardRef` from this component. // NOTE: This wrapper component is necessary because `ScrollView` is a class // component and we need to map `ref` to a differently named prop. This can be // removed when `ScrollView` is a functional component. const ScrollViewWrapper: component( ref?: React.RefSetter, ...props: ScrollViewProps -) = React.forwardRef(function Wrapper( - props: ScrollViewProps, - ref: ?React.RefSetter, -): React.Node { +) = function Wrapper({ + ref, + ...props +}: { + ref?: React.RefSetter, + ...ScrollViewProps, +}): React.Node { return ref == null ? ( ) : ( ); -}); +}; ScrollViewWrapper.displayName = 'ScrollView'; // $FlowExpectedError[prop-missing] ScrollViewWrapper.Context = ScrollViewContext;