Initial commit
This commit is contained in:
.gitignore
app
components.jsoncomponents
mdx-content.tsxpost-preview.tsxtheme-provider.tsx
ui
accordion.tsxalert-dialog.tsxalert.tsxaspect-ratio.tsxavatar.tsxbadge.tsxbreadcrumb.tsxbutton.tsxcalendar.tsxcard.tsxcarousel.tsxchart.tsxcheckbox.tsxcollapsible.tsxcommand.tsxcontext-menu.tsxdialog.tsxdrawer.tsxdropdown-menu.tsxform.tsxhover-card.tsxinput-otp.tsxinput.tsxlabel.tsxmenubar.tsxnavigation-menu.tsxpagination.tsxpopover.tsxprogress.tsxradio-group.tsxresizable.tsxscroll-area.tsxselect.tsxseparator.tsxsheet.tsxsidebar.tsxskeleton.tsxslider.tsxsonner.tsxswitch.tsxtable.tsxtabs.tsxtextarea.tsxtoast.tsxtoaster.tsxtoggle-group.tsxtoggle.tsxtooltip.tsxuse-mobile.tsxuse-toast.ts
hooks
lib
next.config.mjspackage.jsonpnpm-lock.yamlpostcss.config.mjsposts
public
styles
tailwind.config.tstsconfig.json
19
hooks/use-mobile.tsx
Normal file
19
hooks/use-mobile.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
Reference in New Issue
Block a user