Skip to content

useMediaQuery ​

Category
Export Size
505 B
Last Changed
2 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)')

Type Declarations ​

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

Source ​

Source • Demo • Docs

Contributors ​

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

Changelog ​

v10.3.0 on 7/30/2023
f3969 - fix: only add/remove event listeners on query change (#3236)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef
v10.0.0-beta.3 on 4/12/2023
4e7b0 - fix(useWindowSize)!: use media query instead of orientationchange listener (#2919)
v9.3.0 on 9/26/2022
33098 - feat: allow query to be a ref (#2178)

Released under the MIT License.