錯誤信息:
eact.js:20483 Warning: Failed form propType: You provided a value
prop to a form field without an onChange
handler. 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來修改