Skip to content

Commit

Permalink
refactor(useMediaQuery): assert window.matchMedia returns truthy value
Browse files Browse the repository at this point in the history
Falsy checks are a remnant from previous versions of the code before isSupported was introduced, where code path existed that skipped calling window.matchMedia.
  • Loading branch information
Ingramz committed Jul 30, 2023
1 parent a1823e3 commit 330fd8b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/core/useMediaQuery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ export function useMediaQuery(query: MaybeRefOrGetter<string>, options: Configur
cleanup()

mediaQuery = window!.matchMedia(toValue(query))
matches.value = !!mediaQuery?.matches

if (!mediaQuery)
return

if ('addEventListener' in mediaQuery)
mediaQuery.addEventListener('change', handler)
else
// @ts-expect-error deprecated API
mediaQuery.addListener(handler)

matches.value = mediaQuery.matches
})

tryOnScopeDispose(() => {
Expand Down

0 comments on commit 330fd8b

Please sign in to comment.