useViewport
Track the screen viewport (screen width and height).
Return Values
Name | Type | Description |
---|---|---|
width | Number | the viewport width. |
height | Number | the viewport height. |
Example Usage
tsx
import { useViewport } from 'react-pre-hooks';
export default function Example() {
const { width, height } = useViewport();
return (
<main>
<h1>Resize the window.</h1>
<p>
width: {width}, height: {height}
</p>
</main>
);
}
import { useViewport } from 'react-pre-hooks';
export default function Example() {
const { width, height } = useViewport();
return (
<main>
<h1>Resize the window.</h1>
<p>
width: {width}, height: {height}
</p>
</main>
);
}