Skip to content

Input 값에 undefined나 null이 들어오는 경우 발생하는 오류

palsa131 edited this page Dec 14, 2021 · 1 revision

문제 상황

잘 되던 input이 localStorage에서 값을 받아오는 것을 추가했더니 다음과 같은 에러를 내기 시작했다.

A component is changing a controlled input of type text to be uncontrolled. 
Input elements should not switch from controlled to uncontrolled (or vice versa). 
Decide between using a controlled or uncontrolled input element for the lifetime of the component.

원인

원인은 input의 value에 undefined나 null 값이 들어가면 저렇게 경고 문구를 띄워 준다고 한다.

해결

input에 값이 들어가기 전에 null, undefined값 체크를 해서 null, undefined인 경우 ''가 들어가도록 수정하였다.

Clone this wiki locally