Tracks the window dimensions.
An object containing innerHeight and innerWidth.
innerHeight
innerWidth
This hook listens to the resize event and returns the current innerHeight and innerWidth. It handles server-side rendering by returning 0 initially if window is undefined.
resize
window
const { innerWidth, innerHeight } = useWindowSize();return <div>Window size: {innerWidth}x{innerHeight}</div>; Copy
const { innerWidth, innerHeight } = useWindowSize();return <div>Window size: {innerWidth}x{innerHeight}</div>;
Tracks the window dimensions.