LoginSignup
0
0

More than 1 year has passed since last update.

Reactでコンポネントの位置を取得

Posted at

Reactでコンポネントの位置を取得したときのメモ。

ソース(抜粋)
  const myRef = useRef(null);
       
  const buttonClicked = () => {
      if (myRef.current) {
      const { offsetTop, offsetLeft } = myRef.current;
      console.log(`offsetTop=${offsetTop}, offsetLeft=${offsetLeft}`);
       
  return (
       
      <button className="TestButton" onClick={buttonClicked} ref={myRef}>
       

他にも例えばこういうものがある。
innerText
offsetHeight
offsetWidth
offsetLeft
offsetParent
offsetTop

参考

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0