Skip to content

Self-hosted house planner: true-scale 2D floor plan, 3D, satellite map overlay, sewer, electrical, water and underfloor heating with calculations, priced bill of materials. React + PHP, no database. By the team behind homedesignsai.pro

526 B
Raw Blame
import { useSyncExternalStore } from 'react'

const QUERY = '(max-width: 699px), (pointer: coarse) and (not (any-pointer: fine))'

const media = () => (typeof window !== 'undefined' && window.matchMedia ? window.matchMedia(QUERY) : null)

export const isViewOnly = () => !!media()?.matches

export const useViewOnly = () =>
  useSyncExternalStore(
    (cb) => {
      const q = media()
      q?.addEventListener('change', cb)
      return () => q?.removeEventListener('change', cb)
    },
    isViewOnly,
    () => false,
  )