Created
January 22, 2024 22:20
-
-
Save kibolho/24f76105062490dd35dd39a04e600fa7 to your computer and use it in GitHub Desktop.
Hook to check breakpoints of tailwind dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useMediaQuery } from 'usehooks-ts'; | |
| // Define Tailwind's breakpoints | |
| const breakpoints = { | |
| sm: 640, | |
| md: 768, | |
| lg: 1024, | |
| xl: 1280, | |
| '2xl': 1536, | |
| }; | |
| export const useIsBreakpoint = (breakpoint: keyof typeof breakpoints) => { | |
| const query = `(min-width: ${breakpoints[breakpoint]}px)`; | |
| const isBreakpoint = useMediaQuery(query); | |
| return isBreakpoint; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment