-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add useOnClickOutside hook #90
Conversation
@jarrisondev is attempting to deploy a commit to the aforina's projects Team on Vercel. A member of the Team first needs to authorize 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.
Minor improvements, GREAT PR!
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.
Looks mergeable to me too, nice job! 🌮 🌯
type Event = MouseEvent | TouchEvent; | ||
|
||
export const useOnClickOutside = (ref: RefObject<HTMLElement>, handler: (event: Event) => void) => { | ||
useEffect(() => { |
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'd suggest using the latest ref
pattern to avoid forcing the consumer of the hook to memoize the handler function to avoid the event from being bound and unbound on every rerender.
You can see an example here,
Very good PR Jarri! Amazing!! Thanks a lot for the contribution 😁! |
Changes Made 🎉
Describe Changes
Related Issue(s)
#86
Visuals (Optional)
Checklist ✅