Anchor position props.
const anchorRef = useRef(null);
const targetRef = useRef(null);
useAnchorPosition({
getAnchorRect: () => anchorRef.current.getBoundingClientRect(),
getTargetRect: () => targetRef.current.getBoundingClientRect(),
variants: [
{
alignX: 'outerEnd',
alignY: 'center',
},
],
onPositionChange(info) {
targetRef.current.style.transform = `translateX(${info.x}px) translateY(${info.y}px)`;
},
});
<div ref={anchorRef} />
<div
ref={targetRef}
style={{ position: 'fixed' }}
/>
Positions a target element around the anchor element.