useWindowSize()
The
useWindowSize() hook returns the current width and height of the browser window. It uses useSyncExternalStore for optimal performance and concurrent rendering compatibility.Import
typescript
Usage
Try it out: Resize your browser window to see the values update in real-time below.
Width
0px
Height
0px
Component.tsx
API
Arguments
This hook does not accept any arguments.
Returns
Returns an object with the current window dimensions:
width– number The inner width of the browser window (in pixels).height– number The inner height of the browser window (in pixels).