useElementRect
warning
This hook is in the experimental stage.
- This is a hook that provides information obtained through the
getBoundingClientRect()method and thepositionof a specific element.
Features
- It provides the initial
widthof the element and theoffsetWidthafter applying styles. - It provides the initial
heightof the element and theoffsetHeightafter applying styles. - It provides the
offsetLeftposition relative to the parent element, as well as theleftposition within the entire viewport. - It provides the
offsetLeftposition relative to the parent element, as well as theleftposition within the entire viewport. - It provides the
offsetTopposition relative to the parent element, as well as thetopposition within the entire viewport.
Types
const useElementRect: <T extends HTMLElement>(
refresh?: boolean,
) => {
width: number;
height: number;
offsetWidth: number;
offsetHeight: number;
left: number;
top: number;
offsetLeft: number;
offsetTop: number;
ref: React.MutableRefObject<T | null>;
};