Skip to content

Instantly share code, notes, and snippets.

@kibolho
Created January 22, 2024 22:20
Show Gist options
  • Select an option

  • Save kibolho/24f76105062490dd35dd39a04e600fa7 to your computer and use it in GitHub Desktop.

Select an option

Save kibolho/24f76105062490dd35dd39a04e600fa7 to your computer and use it in GitHub Desktop.
Hook to check breakpoints of tailwind dynamically
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