Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mark committed Mar 12, 2023
1 parent 9eaed94 commit 72e845c
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/@core/hooks/useMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ function demo() {
import useMediaQuery from '@mui/material/useMediaQuery'



interface MediaItem {
xs: boolean
sm: boolean
md: boolean
lg: boolean
xl: boolean
xxl: boolean
[key: string]: boolean
}

interface MediaDict {
Expand All @@ -59,20 +59,27 @@ interface MediaDict {
export const useMedia = () => {
// const theme: ThemedProps = useTheme();

const getMedia = () => {
const res: { [key: string]: any } = {
up: {},
down: {},
only: {}
}
for (const i of ['xs', 'sm', 'md', 'lg', 'xl', 'xxl']) {
res.up[i] = useMediaQuery((theme: any) => theme.breakpoints.up(i))
res.down[i] = useMediaQuery((theme: any) => theme.breakpoints.down(i))
res.only[i] = useMediaQuery((theme: any) => theme.breakpoints.only(i))
}

return res as MediaDict
const matches = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl']

const chunks: MediaItem = {
xs: false,
sm: false,
md: false,
lg: false,
xl: false,
xxl: false,
}

const res: MediaDict = {
up: chunks,
down: chunks,
only: chunks,
}
for (const i of matches) {
res.up[i] = useMediaQuery((theme: any) => theme.breakpoints.up(i)) as boolean
res.down[i] = useMediaQuery((theme: any) => theme.breakpoints.down(i)) as boolean
res.only[i] = useMediaQuery((theme: any) => theme.breakpoints.only(i)) as boolean
}

return getMedia()
return res as MediaDict
}

0 comments on commit 72e845c

Please sign in to comment.