Etc/Error
[React] A component is changing an uncontrolled input of type text to be controlled error in ReactJS
모야이거였어
2021. 12. 27. 17:05
원인
만약 input 값에 value를
value={this.state.fields["name"]}
위와 같이 둔다면, 처음 렌더링 동안 빈 객체로 필드 undefined를 얻음!
value={undefined}
그래서 위와같은 에러가 나는것
해결
첫 정의를 아래와 같이 undefined가 안되게 함
this.state = { fields: {name: ''} }
//or
value={this.state.fields.name || ''} // (undefined || '') = ''
A component is changing an uncontrolled input of type text to be controlled error in ReactJS
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 contro...
stackoverflow.com