useRef
Ref object
を返す
あるあるの型付
code:ts
const ref = useRef<HTMLElement>(null);
HTMLElement
か、要素ごとに具体化した型を付ける
ElementRef
が便利なのらしい
@mattpocockuk
: ElementRef is super nice.
Here's how it can make typing useRef easier in React 🧵
https://pbs.twimg.com/media/F148MnEXwAMl7nW.png
参考
React Ref の基本 - 30歳からのプログラミング
https://ja.reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables
https://qiita.com/uhyo/items/246fb1f30acfeb7699da#useref
https://yuheiy.hatenablog.com/entry/2020/02/20/235918
https://zenn.dev/berlysia/articles/624bc1aaffda58
https://qiita.com/uhyo/items/6a3b14950c1ef6974024
https://twitter.com/dan_abramov/status/1099842565631819776
useRef() is basically useState({current: initialValue })[0]