-
Notifications
You must be signed in to change notification settings - Fork 67
refactor(useRefEffect): Improve useRefEffect hook by adding generic types in docs and strict null check in implementation #273
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
Changes from 2 commits
f910eb2
a8ecfc4
bfe5861
8e54596
66ca52f
3e34b87
1f1d360
2e7def8
5e3bdaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,7 +41,7 @@ export function useRefEffect<Element extends HTMLElement = HTMLElement>( | |||||
| cleanupCallbackRef.current(); | ||||||
| cleanupCallbackRef.current = () => {}; | ||||||
|
|
||||||
| if (element == null) { | ||||||
| if (element === null) { | ||||||
|
||||||
| if (element === null) { | |
| if (element == null) { |
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.
Since instance is of type T | null as in React CallbackRef Type, I don't think we need to check for undefined. What do you think?
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.
You're right! — since the type is T | null, === null works correctly here.
That said, our codebase uses == null as the convention (see mergeRefs, mergeProps, debounce, etc.), so how about keep it consistent and revert to == null??
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.
I think it would be better to stick to the existing conventions!
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.
On the generic naming — I agree that the current source
Elementshadows the global DOM type, so a rename makes senseHowever, our convention avoids abbreviations, so
Emight not be the best fit. What do you think about using a full name likeTargetElementorRefElementinstead? Or if you have another idea, happy to hear it!If we go with a rename, it'd be great to update both the source and docs together so they stay in sync.
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.
I used abbreviations based on the useLongPress and mouseDoubleClick documentation, but both hooks are now deprecated🤔
RefElement looks good :)
We will update both the source code and documentation!