Skip to content

The VS Code of video editing, built for agents.

TypeScript
757 B
Raw Blame
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://github.com/solidjs-community/solid-primitives/blob/main/packages/media/src/index.ts

import { createSignal, onCleanup } from "solid-js"
import { isServer } from "solid-js/web"

export const useIsMobile = () => {
  if (isServer) {
    return () => false
  }

  const mql = window.matchMedia("(max-width: 767px)")
  const [state, setState] = createSignal(mql.matches)
  const update = () => setState(mql.matches)
  mql.addEventListener("change", update)
  onCleanup(() => {
    mql.removeEventListener("change", update)
  })
  return state
}