Skip to content
On this page

useMediaQuery

Category
Export Size
1.02 kB
Last Changed
3 months ago

Reactive Media Query. Once you've created a MediaQueryList object, you can check the result of the query or receive notifications when the result changes.

Demo

isLargeScreen: false
prefersDark: false

Usage

js
import { useMediaQuery } from '@vueuse/core'

const isLargeScreen = useMediaQuery('(min-width: 1024px)')
const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)')
import { useMediaQuery } from '@vueuse/core'

const isLargeScreen = useMediaQuery('(min-width: 1024px)')
const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)')

Type Declarations

typescript
/**
 * Reactive Media Query.
 *
 * @see https://vueuse.org/useMediaQuery
 * @param query
 * @param options
 */
export declare function useMediaQuery(
  query: MaybeComputedRef<string>,
  options?: ConfigurableWindow
): Ref<boolean>
/**
 * Reactive Media Query.
 *
 * @see https://vueuse.org/useMediaQuery
 * @param query
 * @param options
 */
export declare function useMediaQuery(
  query: MaybeComputedRef<string>,
  options?: ConfigurableWindow
): Ref<boolean>

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
Young
Jelf
Dominik Freier
webfansplz
Eureka
karma
Alex Kozack
Jacob Clevenger

Changelog

v9.3.0 on 9/26/2022
33098 - feat: allow query to be a ref (#2178)
v8.9.2 on 7/12/2022
81d92 - fix(all)!: isSupported becomes Ref instead of boolean for SSR compatibility (#1800)
v8.8.1 on 7/6/2022
60f9a - fix: check if window.matchMedia is a function (#1765)
v8.8.0 on 7/6/2022
5a64c - fix: strict isSupported check
v8.5.0 on 5/16/2022
0222d - fix: normalize isSupported flag (#1575)
v8.2.1 on 3/30/2022
7edd0 - fix: media query before mount (#1461)
v8.0.1 on 3/14/2022
92ced - fix: removeEventListener in guard target should be med… (#1401)
v7.0.2 on 11/23/2021
7b67d - feat: improve SSR

Released under the MIT License.