domain-watchdog/assets/hooks/useBreakpoint.tsx

20 lines
552 B
TypeScript
Raw Normal View History

2024-07-30 06:13:31 +02:00
import { Breakpoint, theme } from 'antd';
import { useMediaQuery } from 'react-responsive';
const { useToken } = theme;
type ScreenProperty = 'screenXXL' | 'screenXL' | 'screenLG' | 'screenMD' | 'screenSM' | 'screenXS';
const propertyName = (breakpoint: Breakpoint): ScreenProperty => {
return 'screen' + breakpoint.toUpperCase() as ScreenProperty
};
export default function useBreakpoint(
breakpoint: Breakpoint
) {
const { token } = useToken()
const width: number = token[propertyName(breakpoint)]
return useMediaQuery({maxWidth: width})
}