尤川豪   ·  3年前
445 貼文  ·  275 留言

React ref 在 React Hook Form 裡面的應用

ref

Ref 的值會根據節點的類型而有所不同:

  • 當在 HTML element 上使用 ref 參數時,使用 React.createRef() 建立 ref 會取得它底下的 DOM element 來做為它的 current 屬性。
  • 當在客製化的 class component 使用 ref 參數時,ref 取得被 mount 的 component 上的 instance 來當作他的 current。
  • 你不能在 function component 上使用 ref,因為他們沒有 instance。

register

controller

  分享   共 1,339 次點閱
共有 1 則留言
Lin Chen   ·  3年前
2 貼文  ·  7 留言

Functional component有useRef可使用 有些case滿好用的! (ex做一個倒數計時器,希望數字每秒遞減,卻不希望整個component re-render)

 
按了喜歡:
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章