-
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
Convert usePrevious
hook to TypeScript.
#35597
Conversation
usePrevious
hook to TypeScript.
Size Change: -3 B (0%) Total Size: 1.07 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! Though just for the record I think this falls under refactoring for refactoring's sake (which is against the WP coding guidelines). Uplifting code that currently isn't type checked (either using JSDoc or TypeScript) is definitely more desirable than converting JSDoc checked files to native TypeScript.
But anyway, this code is definitely a lot cleaner and more comprehensible than the JSDoc version, so thank you 😁
Description
Part of #18838.
Using TypeScript, we can get rid of a type assertion in the
usePrevious
hook, and even avoid explicitly passingundefined
to the initialuseRef
call, so that's what I did in this PR. The implementation is now more or less identical to theusePrevious
hook in several other projects:useIsomorphicLayoutEffect
rather thanuseEffect
, which is interesting)Checklist:
*.native.js
files for terms that need renaming or removal).