From 4c55e94dc5aeb0656c77c3e1964b0179c6a40cd2 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 6 Sep 2024 04:30:17 -0700 Subject: [PATCH] remove unnecessary useRef (#46351) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46351 changelog: [internal] useRef here is not needed, let's remove it. Reviewed By: yungsters Differential Revision: D62235850 fbshipit-source-id: 77d50152f5423e8806cc28c18bcaf4803076e813 --- .../Libraries/Animated/useAnimatedProps.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/react-native/Libraries/Animated/useAnimatedProps.js b/packages/react-native/Libraries/Animated/useAnimatedProps.js index 0ed02fb7b66..f105b666a9c 100644 --- a/packages/react-native/Libraries/Animated/useAnimatedProps.js +++ b/packages/react-native/Libraries/Animated/useAnimatedProps.js @@ -247,16 +247,15 @@ function addAnimatedValuesListenersToProps( function useAnimatedPropsLifecycle_layoutEffects(node: AnimatedProps): void { const prevNodeRef = useRef(null); const isUnmountingRef = useRef(false); - const userDrivenAnimationEndedListener = useRef(null); useEffect(() => { // It is ok for multiple components to call `flushQueue` because it noops // if the queue is empty. When multiple animated components are mounted at // the same time. Only first component flushes the queue and the others will noop. NativeAnimatedHelper.API.flushQueue(); - + let drivenAnimationEndedListener: ?EventSubscription = null; if (node.__isNative) { - userDrivenAnimationEndedListener.current = + drivenAnimationEndedListener = NativeAnimatedHelper.nativeEventEmitter.addListener( 'onUserDrivenAnimationEnded', data => { @@ -266,10 +265,7 @@ function useAnimatedPropsLifecycle_layoutEffects(node: AnimatedProps): void { } return () => { - if (userDrivenAnimationEndedListener.current) { - userDrivenAnimationEndedListener.current?.remove(); - userDrivenAnimationEndedListener.current = null; - } + drivenAnimationEndedListener?.remove(); }; });