react 表單受控和非受控

參見:https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/javascript

非受控:java

onSubmit = ()=>{
  const val = this._input.value;  
}

<input ref={input =>this._input=input}>

  

受控:value propreact

 

選擇異步

一、若form簡單,值能夠一次性在提交時候檢索或驗證,則優先使用非受控,簡單this

二、實時驗證、異步表單數據、組合驗證等,須要實時使用表單中的值,則使用受控組件orm

相關文章
相關標籤/搜索