MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / useIsMobile

Function useIsMobile

apps/baseai.dev/src/lib/hooks/use-is-mobile.tsx:12–32  ·  view source on GitHub ↗

* Custom hook that returns a boolean indicating whether the current device is a mobile device. * It listens for window resize events and updates the value accordingly. * * @returns {boolean} - A boolean value indicating whether the current device is a mobile device.

()

Source from the content-addressed store, hash-verified

10 * @returns {boolean} - A boolean value indicating whether the current device is a mobile device.
11 */
12function useIsMobile() {
13 const [isMobile, setIsMobile] = useState(false);
14
15 useEffect(() => {
16 function handleResize() {
17 const isMobileDevice = window.innerWidth < MOBILE_BREAKPOINT;
18 setIsMobile(isMobileDevice);
19 }
20
21 // Add event listener
22 window.addEventListener('resize', handleResize);
23
24 // Call handler right away so state gets updated with initial window size
25 handleResize();
26
27 // Remove event listener on cleanup
28 return () => window.removeEventListener('resize', handleResize);
29 }, []); // Empty array ensures effect runs only on mount and unmount
30
31 return isMobile;
32}
33
34export default useIsMobile;

Callers

nothing calls this directly

Calls 1

handleResizeFunction · 0.85

Tested by

no test coverage detected