react.js Warning: Failed form propType: You provided a value prop to a form field without an onChange handler. This will render a read-only field.


錯誤信息:

eact.js:20483 Warning: Failed form propType: You provided a value prop to a form field without an onChangehandler. This will render a read-only field. If the field should be mutable use defaultValue. Otherwise, set either onChange or readOnly. Check the render method of TickTock.

原因:

如果設置value,那value就永遠是設置的那個值,要通過輸入內容改變只能通過onChange,要么就把這個input設置成readOnly的

英文講得很明白,如果你希望的是給字段賦初值那就用 defaultValue,如果用了類似 <input value={1} />這種,那這個輸入框的值將永遠為1,無法通過輸入來更改,只能通過onChange來修改


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM