鍍金池/ 問(wèn)答/HTML/ input后臺(tái)報(bào)錯(cuò)

input后臺(tái)報(bào)錯(cuò)

圖片描述

bundle.js:176418 Warning: A component 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...

回答
編輯回答
遲月

這個(gè)原因就是受控組件與非受控組件的問(wèn)題。你在初始的時(shí)候?qū)alue的值設(shè)置為undefined了。
所以修改為:

<input onChange={e => handleChange('user', e)} value={this.state.data.name || ''} />
2018年1月17日 17:46