A React Hooks package for boundingclientrect
npm install @rooks/use-boundingclientrect```
npm install rooks
or
``
yarn add rooks
Rooks is completely treeshakeable and if you use only 1 of the 50+ hooks in the package, only that hook will be bundled with your code. Your bundle will only contain the hooks that you need. Cheers!
``
npm install rooks
or
``
yarn add rooks
Rooks is completely treeshakeable and if you use only 1 of the 50+ hooks in the package, only that hook will be bundled with your code. Your bundle will only contain the hooks that you need. Cheers!
!Build Status   
``
npm install --save @rooks/use-boundingclientrect
`javascript`
import useBoundingclientrect from "@rooks/use-boundingclientrect"
`jsx
function Demo() {
const myRef = useRef();
const getBoundingClientRect = useBoundingclientrect(myRef);
const [XOffset, setXOffset] = useState(0);
const [YOffset, setYOffset] = useState(300);
const displayString = JSON.stringify(getBoundingClientRect, null, 2);
return (
<>
style={{
width: 300,
background: "lightblue",
padding: "10px",
position: "absolute",
left: XOffset,
top: YOffset
}}
ref={myRef}
>
style={{
resize: "both",
overflow: "auto",
background: "white",
color: "blue",
maxWidth: "100%"
}}
>
Resize this div as you see fit. To demonstrate that it also updates
on child dom nodes resize
{displayString}render(
``
| Argument | Type | Description |
| -------- | --------- | ------------------------------------------------- |
| ref | React ref | React ref whose boundingClientRect is to be found |
| Return value | Type | Description | Default value |
| ------------ | ------- | ---------------------------------------------------------------------------- | ------------- |
| value | DOMRect | DOMRect Object containing x,y, width, height, left,right,top and bottom keys | null |