hub-stats / hooks /useIsMobile.ts
Caleb Fahlgren
only show main chart on mobile due to compute resources on mobile phones
d59a538
raw
history blame contribute delete
413 Bytes
import { useState, useEffect } from 'react';
export function useIsMobile() {
const [isMobile, setIsMobile] = useState(true);
useEffect(() => {
const checkIfMobile = () => {
setIsMobile(window.innerWidth < 768);
};
checkIfMobile();
window.addEventListener('resize', checkIfMobile);
return () => window.removeEventListener('resize', checkIfMobile);
}, []);
return isMobile;
}