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