diff options
Diffstat (limited to 'packages/hooks')
| -rw-r--r-- | packages/hooks/use-keypress.ts | 16 | ||||
| -rw-r--r-- | packages/hooks/use-mobile.ts | 24 |
2 files changed, 21 insertions, 19 deletions
diff --git a/packages/hooks/use-keypress.ts b/packages/hooks/use-keypress.ts index 42906660..eee23acb 100644 --- a/packages/hooks/use-keypress.ts +++ b/packages/hooks/use-keypress.ts @@ -1,15 +1,15 @@ -import { useEffect } from "react" +import { useEffect } from "react"; export const useKeyPress = (key: string, callback: () => void) => { useEffect(() => { const handler = (e: KeyboardEvent) => { if (e.key === key && e.altKey) { - callback() + callback(); } - } - window.addEventListener("keydown", handler) + }; + window.addEventListener("keydown", handler); return () => { - window.removeEventListener("keydown", handler) - } - }, [key, callback]) -} + window.removeEventListener("keydown", handler); + }; + }, [key, callback]); +}; diff --git a/packages/hooks/use-mobile.ts b/packages/hooks/use-mobile.ts index 283bbb4c..0a892310 100644 --- a/packages/hooks/use-mobile.ts +++ b/packages/hooks/use-mobile.ts @@ -1,19 +1,21 @@ -import * as React from "react" +import * as React from "react"; -const MOBILE_BREAKPOINT = 768 +const MOBILE_BREAKPOINT = 768; export function useIsMobile() { - const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined) + const [isMobile, setIsMobile] = React.useState<boolean | undefined>( + undefined, + ); React.useEffect(() => { - const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) + const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`); const onChange = () => { - setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) - } - mql.addEventListener("change", onChange) - setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) - return () => mql.removeEventListener("change", onChange) - }, []) + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); + }; + mql.addEventListener("change", onChange); + setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); + return () => mql.removeEventListener("change", onChange); + }, []); - return !!isMobile + return !!isMobile; } |