useWindowSize
Aboutβ
Window size hook for React.
Installationβ
npm install --save rooks
Importing the hookβ
import {useWindowSize} from "rooks
Usageβ
function WindowComponent() {
const { innerWidth, innerHeight, outerHeight, outerWidth } = useWindowSize();
return (
<div>
<p>
<span>innerHeight - </span>
<span>{innerHeight}</span>
</p>
<p>
<span>innerWidth - </span>
<span>{innerWidth}</span>
</p>
<p>
<span>outerHeight - </span>
<span>{outerHeight}</span>
</p>
<p>
<span>outerWidth - </span>
<span>{outerWidth}</span>
</p>
</div>
);
}
render(<WindowComponent />);
Returned Object keysβ
Returned object attributes | Type | Description |
---|---|---|
width | int | inner width of window |
height | int | inner height of window |
outerWidth | int | outer height of window |
outerHeight | int | outer width of window |
Codesandbox Exampleβ
Basic usageβ
Join Bhargav's discord serverβ
You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.