Components: refactorDraggable to pass exhaustive-deps#41499
Conversation
|
Size Change: 0 B Total Size: 1.24 MB ℹ️ View Unchanged
|
fluiddot
left a comment
There was a problem hiding this comment.
LGTM 🎊 !
I tested the changes in both Android and iOS platforms and confirm that the change doesn't modify the draggable logic.
| const providerValue = useMemo( () => { | ||
| return { panGestureRef, isDragging, isPanActive, draggingId }; | ||
| }, [] ); | ||
| }, [ isDragging, isPanActive, draggingId ] ); |
There was a problem hiding this comment.
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
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.
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.
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 👍 .
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
Draggablecomponent to satisfy theexhaustive-depseslint rule (specifically by updating theControlPointssubcomponent)Why?
Part of the effort in #41166 to apply
exhuastive-depsto the Components packageHow?
Add the three values returned as an object by
useMemoto 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