본문 바로가기
개발/React

[react] Warning: A component is changing an uncontrolled input to be controlled...

by 코딩하는 갓디노 2022. 1. 7.

[react] Warning: A component is changing an uncontrolled input to be controlled

 

react에서 <input /> 태그 사용후 
나온 warning입니다.

 

Warning 오류 

Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.

 

input의 value에 undefined가 들어갔을 경우에 대한 처리가 없는다는 경고메시지 입니다. 

 

before

<input type="number" name="weight" value={patientRevData.weight} onChange={onChangeData} />

 

 

Warning 해결 방법

  • input의 value가 undefined일 때 ''가 들어올 수 있도록 함
  • value={value || ' '}
<input type="number" name="weight" value={patientRevData.weight || ""} onChange={onChangeData} />

 

반응형

댓글