Skip to content

Instantly share code, notes, and snippets.

@ImKubass
Last active March 21, 2023 23:54
Show Gist options
  • Save ImKubass/4b7e89ef41d0fa8ee28776d9cf3f14de to your computer and use it in GitHub Desktop.
Save ImKubass/4b7e89ef41d0fa8ee28776d9cf3f14de to your computer and use it in GitHub Desktop.
const mobileQuery = window.matchMedia("(max-width: 74.999em)") // Change to your needs
const handleMobileChange = (mediaQueryList: MediaQueryListEvent | MediaQueryList) => {
if (mediaQueryList.matches) {
// Its Mobile
} else {
// Its Desktop
}
}
mobileQuery.addEventListener("change", handleMobileChange)
handleMobileChange(mobileQuery) // Init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment