-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components: refactorDraggable
to pass exhaustive-deps
#41499
Conversation
Size Change: 0 B Total Size: 1.24 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎊 !
I tested the changes in both Android and iOS platforms and confirm that the change doesn't modify the draggable logic.
@@ -142,7 +142,7 @@ const Draggable = ( { | |||
|
|||
const providerValue = useMemo( () => { | |||
return { panGestureRef, isDragging, isPanActive, draggingId }; | |||
}, [] ); | |||
}, [ isDragging, isPanActive, draggingId ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDragging
, isPanActive
and draggingId
are shared value object types created using the hook useSharedValue
provided by the React Native's Reanimated library.
gutenberg/packages/components/src/draggable/index.native.js
Lines 48 to 50 in 3512a38
const isDragging = useSharedValue( false ); | |
const isPanActive = useSharedValue( false ); | |
const draggingId = useSharedValue( '' ); |
The shared values are similar to the React references in the sense that their value doesn't update after they are initialized. Therefore, it's not really necessary to add them as dependencies of useMemo
because the value won't change. However, I understand that since this type is not recognized by the exhuastive-deps
ESLint rule, we could add them in order to comply with it 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fluiddot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you both!
Maybe we could leave an inline comment in code, so that the next time folks look at this line of code they have more context about isDragging
, isPanActive
and draggingId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep good point, we could leave a comment when using the shared value objects in hooks to outline that they are not required to be added in the dependencies array 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny follow-up opened in #41658
3512a38
to
8567280
Compare
…41499) * Draggable: update `useEffect` dependency array * Draggable: update changelog (merge conflict) * move changelog update to the correct section
What?
Updates the
Draggable
component to satisfy theexhaustive-deps
eslint rule (specifically by updating theControlPoints
subcomponent)Why?
Part of the effort in #41166 to apply
exhuastive-deps
to the Components packageHow?
Add the three values returned as an object by
useMemo
to the dependency array so they're current.Previously this was an empty array so it would only occur on the initial render. I'm not 100% sure if was intentional or not. My testing of this change didn't raise any red flags, but I'd love some feedback from someone more familiar with React native (cc @geriux)
Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src/draggable