|
|
@@ -1,4 +1,4 @@
|
|
|
-import { RefObject } from 'react';
|
|
|
+import { RefObject, useEffect } from 'react';
|
|
|
|
|
|
import {
|
|
|
isClient, isServer, pagePathUtils, Nullable, PageGrant,
|
|
|
@@ -177,21 +177,21 @@ export const useIsDeviceSmallerThanMd = (): SWRResponse<boolean, Error> => {
|
|
|
|
|
|
const { cache, mutate } = useSWRConfig();
|
|
|
|
|
|
- if (isClient()) {
|
|
|
- const mdOrAvobeHandler = function(this: MediaQueryList): void {
|
|
|
- // sm -> md: matches will be true
|
|
|
- // md -> sm: matches will be false
|
|
|
- mutate(key, !this.matches);
|
|
|
- };
|
|
|
- const mql = addBreakpointListener(Breakpoint.MD, mdOrAvobeHandler);
|
|
|
+ useEffect(() => {
|
|
|
+ if (isClient()) {
|
|
|
+ const mdOrAvobeHandler = function(this: MediaQueryList): void {
|
|
|
+ // sm -> md: matches will be true
|
|
|
+ // md -> sm: matches will be false
|
|
|
+ mutate(key, !this.matches);
|
|
|
+ };
|
|
|
+ const mql = addBreakpointListener(Breakpoint.MD, mdOrAvobeHandler);
|
|
|
|
|
|
- // initialize
|
|
|
- if (cache.get(key) == null) {
|
|
|
- document.addEventListener('DOMContentLoaded', () => {
|
|
|
+ // initialize
|
|
|
+ if (cache.get(key) == null) {
|
|
|
mutate(key, !mql.matches);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }, [cache, key, mutate]);
|
|
|
|
|
|
return useStaticSWR(key);
|
|
|
};
|
|
|
@@ -201,21 +201,21 @@ export const useIsDeviceSmallerThanLg = (): SWRResponse<boolean, Error> => {
|
|
|
|
|
|
const { cache, mutate } = useSWRConfig();
|
|
|
|
|
|
- if (isClient()) {
|
|
|
- const lgOrAvobeHandler = function(this: MediaQueryList): void {
|
|
|
- // md -> lg: matches will be true
|
|
|
- // lg -> md: matches will be false
|
|
|
- mutate(key, !this.matches);
|
|
|
- };
|
|
|
- const mql = addBreakpointListener(Breakpoint.LG, lgOrAvobeHandler);
|
|
|
+ useEffect(() => {
|
|
|
+ if (isClient()) {
|
|
|
+ const lgOrAvobeHandler = function(this: MediaQueryList): void {
|
|
|
+ // md -> lg: matches will be true
|
|
|
+ // lg -> md: matches will be false
|
|
|
+ mutate(key, !this.matches);
|
|
|
+ };
|
|
|
+ const mql = addBreakpointListener(Breakpoint.LG, lgOrAvobeHandler);
|
|
|
|
|
|
- // initialize
|
|
|
- if (cache.get(key) == null) {
|
|
|
- document.addEventListener('DOMContentLoaded', () => {
|
|
|
+ // initialize
|
|
|
+ if (cache.get(key) == null) {
|
|
|
mutate(key, !mql.matches);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }, [cache, key, mutate]);
|
|
|
|
|
|
return useStaticSWR(key);
|
|
|
};
|