文章詳情頁
node.js - antdesign的Input控件加了初始化值,網站控制臺暴警告,什么原因?
瀏覽:105日期:2024-08-05 15:17:10
問題描述
這句話爆了警告
即:Warning: Input is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlle...如果,我在initailValue傳入不變的量string,就不會暴警告
為什么 呢?
問題解答
回答1:我也有這樣的問題,因為只是warn不是error不影響開發就沒管
回答2:你報的錯最后的那個鏈接中,有提到:A controlled <input> has a value prop。而你的代碼中,并沒有出現value屬性。
而你將一個函數執行結果放入input中的作法,個人覺得不可取。你應事先以一個變量保存此函數的執行結果,再將變量放入input中,就如formItemLayout一樣,我覺得這樣更好
排行榜
