Last active
January 11, 2021 07:52
-
-
Save KajSzy/564e25e384074918d873ef7602b2a094 to your computer and use it in GitHub Desktop.
Example of using Template Literal Types introduced in Typescript 4.1
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, useTheme } from '@material-ui/core'; | |
| type Devices = 'mobile' | 'tablet' | 'desktop'; | |
| type DeviceKey = `is${Capitalize<Devices>}`; | |
| export const useBreakpoints = (): Record<DeviceKey, boolean> => { | |
| const theme = useTheme(); | |
| return { | |
| isMobile: useMediaQuery(theme.breakpoints.down('sm')), | |
| isTablet: useMediaQuery(theme.breakpoints.between('sm', 'md')), | |
| isDesktop: useMediaQuery(theme.breakpoints.up('md')), | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment