-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: refactor Notice
to pass exhaustive-deps
#44157
Conversation
Size Change: 0 B Total Size: 1.26 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.
Code-wise the changes seem correct, but we'll need to wait for folks from the native team to test this
Hey there 👋
Sure! I'll check it out 👍 |
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've tested this on both iOS and Android and it works as expected. 🚀
What?
Refactor the Notice component to ignore the
exhaustive-deps
eslint rule. This specifically impacts the*.native
version of the componentsWhy?
Part of the effort in #41166 to apply
exhuastive-deps
to the Components packageHow?
In
index.native.js
:Because
startAnimation
is not called anywhere else, its code can be moved directly into theuseEffect
call. This eliminates the need forstartAnimation
as a dependency, but it brings dependencies of its own:animationValue
is actually aRef
object, so it should remain stable and safe to list as a dependencyonHide
would cause endless re-renders, so it gets wrapped in its ownuseCallback
to ensure referencial equality.id
is needed as a dependency foronHide
's newuseCallback
. This should be a unique value to the current notice, and not something that should change (though I lost the thread on tracking it. It looks like it's coming from the@wordpress/notices
store.)onNoticeHidden
is a dependency of both the originaluseEffect
and the newuseCallback
. It's a prop passed in fromlist.native.js
, and would cause unwanted re-renders, so more changes were needed there.In
list.native.js
:onNoticeHidden
was is being passed theonRemove
method. To prevent endless re-renders do an unstable reference there, we can wraponRemove
in its ownuseCallback
. The only dependency here would be theremoveNotice
method, which should be always be a stable reference because it's a dispatch function.Because all of these changes are in the native components, I lack a good means for testing... @geriux, would you be able to take a look at these changes?
Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src/notice