mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 00:51:12 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
30
src-old/hooks/use-mobile.tsx
Normal file
30
src-old/hooks/use-mobile.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import * as React from "react";
|
||||
|
||||
const MOBILE_BREAKPOINT = 768;
|
||||
|
||||
export function useIsMobile(): boolean | undefined {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined);
|
||||
|
||||
React.useEffect(() => {
|
||||
// Guard against server-side rendering
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
||||
|
||||
// Use MediaQueryList.matches instead of window.innerWidth for consistency
|
||||
const onChange = () => {
|
||||
setIsMobile(mql.matches);
|
||||
};
|
||||
|
||||
// Set initial value
|
||||
setIsMobile(mql.matches);
|
||||
|
||||
// Listen for changes
|
||||
mql.addEventListener("change", onChange);
|
||||
|
||||
// Cleanup listener on unmount
|
||||
return () => mql.removeEventListener("change", onChange);
|
||||
}, []);
|
||||
|
||||
return isMobile;
|
||||
}
|
||||
Reference in New Issue
Block a user