UNPKG

@thibault.sh/hooks

Version:

A comprehensive collection of React hooks for browser storage, UI interactions, and more

38 lines (36 loc) 909 B
interface WindowSize { width: number; height: number; } /** * Hook that tracks the browser window dimensions and updates on resize. * * Automatically listens for window resize events and provides the current * width and height. Safe for SSR environments by checking for window availability. * * @returns An object containing: * - `width`: Current window inner width in pixels * - `height`: Current window inner height in pixels * * @example * ```tsx * function ResponsiveComponent() { * const { width, height } = useWindowSize(); * * return ( * <div> * <p>Window size: {width} x {height}</p> * {width < 768 ? ( * <MobileLayout /> * ) : ( * <DesktopLayout /> * )} * </div> * ); * } * ``` * * @see https://thibault.sh/hooks/use-window-size */ declare function useWindowSize(): WindowSize; export { useWindowSize };