const getBreakpoint = (w, h) => ({
  isMobile: w <= 480,
  isTablet: w > 480 && w <= 768,
  isDesktop: w > 768,
  isShortScreen: h < 500,
  isUltrawide: w > 1920 && w / h > 2.0,
});

function useBreakpoint() {
  const [bp, setBp] = React.useState(() => getBreakpoint(window.innerWidth, window.innerHeight));

  React.useEffect(() => {
    let raf;
    const handler = () => {
      cancelAnimationFrame(raf);
      raf = requestAnimationFrame(() => setBp(getBreakpoint(window.innerWidth, window.innerHeight)));
    };
    window.addEventListener('resize', handler);
    return () => {
      cancelAnimationFrame(raf);
      window.removeEventListener('resize', handler);
    };
  }, []);

  return bp;
}

Object.assign(window, { useBreakpoint });
