Skip to content

Commit

Permalink
Handle Safari < 14.
Browse files Browse the repository at this point in the history
  • Loading branch information
tvandort committed Oct 23, 2024
1 parent 9f51bcd commit 0500406
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions clients/fides-js/src/lib/hooks/useMediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ export const useMediaQuery = (query: string) => {
function handleChange(e: MediaQueryListEvent) {
setMatches(e.matches);
}
matchQueryList.addEventListener("change", handleChange);

if (matchQueryList.addEventListener) {
matchQueryList.addEventListener("change", handleChange);
} else {
// Supports Safari < 14
matchQueryList.addListener(handleChange);
}
return () => {
matchQueryList.removeEventListener("change", handleChange);
if (matchQueryList.removeEventListener) {
matchQueryList.removeEventListener("change", handleChange);
} else {
// Supports Safari < 14
matchQueryList.removeListener(handleChange);
}
};
}, [query]);
return matches;
Expand Down

0 comments on commit 0500406

Please sign in to comment.