-
Notifications
You must be signed in to change notification settings - Fork 5
feat(useMediaQuery): enhance hook with debounce, fallback and onChange #95
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@barso/forms
@barso/helpers
@barso/hooks
@barso/infra
@barso/ui
commit: |
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.
Pull request overview
This PR enhances the useMediaQuery hook with debouncing capabilities, SSR fallback support, and an onChange callback. The implementation leverages React 18's useSyncExternalStore for improved consistency and SSR safety.
Changes:
- Refactored hook to use
useSyncExternalStorefor better React 18 compatibility - Added debounce support to prevent excessive re-renders during rapid media query changes
- Added fallback option for SSR and hydration scenarios (supports both boolean values and functions)
- Added onChange callback for side effects when media query state changes
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
packages/hooks/src/useMediaQuery/useMediaQuery.js |
Complete rewrite implementing new features using useSyncExternalStore, debounce logic, fallback handling, and onChange callback |
packages/hooks/src/useMediaQuery/useMediaQuery.test.js |
Added tests for debounce functionality, onChange callback, and SSR fallback scenarios |
packages/hooks/src/useMediaQuery/README.md |
New comprehensive documentation with usage examples, API reference, and Next.js integration guide |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…d onChange callback
adef03d to
371d71c
Compare
useMediaQuery