viberss

RSS feed aggregator with a vibecoded reader app.
git clone https://unitehenry.com/git/viberss.git
Log | Files | Refs | README

use-mobile.ts (572B)


      1 import * as React from "react"
      2 
      3 const MOBILE_BREAKPOINT = 768
      4 
      5 export function useIsMobile() {
      6   const [isMobile, setIsMobile] = React.useState<boolean>(() => {
      7     const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
      8     return mql.matches
      9   })
     10 
     11   React.useEffect(() => {
     12     const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
     13     const onChange = () => {
     14       setIsMobile(mql.matches)
     15     }
     16     mql.addEventListener("change", onChange)
     17     return () => mql.removeEventListener("change", onChange)
     18   }, [])
     19 
     20   return isMobile
     21 }