if I want to receive a ref from this:
const ref1=useRef() const ref2=useRef() <div ref=ref1> <div ref=ref2> </div> </div>
if I use ref2.current.offsetTop I get the offset of ref1, is there a way to get ref2 offset value?
ref2.current.offsetTop
You can use Element.getBoundingClientRect() to get information about the element position relative to the viewport:
const {x,y} = ref2.current.getBoundingClientRect(); window.scrollTo(x,y)
1.4m articles
1.4m replys
5 comments
57.0k users