Akshay

useWindowSize

Component

About

useWindowSize is a custom React hook that tracks the current dimensions of the browser window (width and height) in real time. It listens for the resize event and updates whenever the window size changes. This is particularly useful for responsive UI adjustments, conditional rendering based on viewport width, or dynamic layout calculations.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds useWindowSize to your project and fits it to your theme.

Code

How useWindowSize is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { useWindowSize } from "@/components/ui/use-window-size";

export default function DemoOne() {
  const window = useWindowSize();
  return <pre>{JSON.stringify(window)}</pre>;
}

More by Akshay

View all
  • animated-theme-toggle

    animated-theme-toggle

    474