leeda-cloud

[React] 에러 - A component is changing a controlled input to be uncontrolled. 해결법 본문

에러

[React] 에러 - A component is changing a controlled input to be uncontrolled. 해결법

leeda-cloud 2022. 11. 25. 13:55

React 중 콘솔창에 아래와 같은 경고가 뜬다.

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

 

이는 input value가 undefined 이기에 해당 문구가 뜨는 것이다.

 

value에 기본값을 주던가( useState("") ) 아니면 value={ value || "" }로 변경한다.

 

 

 

Comments