Browse Source

[fix]: add-listner is deprecated, switched those to add-event-listner (#4093)

main
CatsAndDogs123 3 years ago
committed by GitHub
parent
commit
86eb509781
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      beta/src/components/Layout/useMediaQuery.tsx
  2. 2
      beta/src/pages/_document.tsx

4
beta/src/components/Layout/useMediaQuery.tsx

@ -17,14 +17,14 @@ const useMediaQuery = (width: number) => {
useEffect(() => { useEffect(() => {
const media = window.matchMedia(`(max-width: ${width}px)`); const media = window.matchMedia(`(max-width: ${width}px)`);
media.addListener(updateTarget); media.addEventListener('change', updateTarget);
// Check on mount (callback is not called until a change occurs) // Check on mount (callback is not called until a change occurs)
if (media.matches) { if (media.matches) {
setTargetReached(true); setTargetReached(true);
} }
return () => media.removeListener(updateTarget); return () => media.removeEventListener('change', updateTarget);
}, [updateTarget, width]); }, [updateTarget, width]);
return targetReached; return targetReached;

2
beta/src/pages/_document.tsx

@ -46,7 +46,7 @@ class MyDocument extends Document {
} }
setTheme(initialTheme); setTheme(initialTheme);
darkQuery.addListener(function (e) { darkQuery.addEventListener('change', function (e) {
if (!preferredTheme) { if (!preferredTheme) {
setTheme(e.matches ? 'dark' : 'light'); setTheme(e.matches ? 'dark' : 'light');
} }

Loading…
Cancel
Save