Skip to content

Commit

Permalink
fix: fallback to previous MQL api for Safari <14
Browse files Browse the repository at this point in the history
  • Loading branch information
apostolos committed Sep 6, 2024
1 parent fa21732 commit f014e58
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions client/hooks/useMediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ export function useMediaQuery(query: string, serverFallback: boolean = false): b
return [
() => mediaQueryList.matches,
(notify: () => void) => {
mediaQueryList.addEventListener('change', notify);
if ('addEventListener' in mediaQueryList) {
mediaQueryList.addEventListener('change', notify);
} else {
//@ts-expect-error - Needed for Safari 13
mediaQueryList.addListener(notify);
}
return () => {
mediaQueryList.removeEventListener('change', notify);
if ('removeEventListener' in mediaQueryList) {
mediaQueryList.removeEventListener('change', notify);
} else {
//@ts-expect-error - Needed for Safari 13
mediaQueryList.removeListener(notify);
}
};
},
() => serverFallback,
Expand Down

0 comments on commit f014e58

Please sign in to comment.