Warning: A component is changing an uncontrolled input to be controlled. 해결법

lynn·2022년 7월 28일
0

문제 해결

목록 보기
4/4

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.

원인

해당 컴포넌트는 제어되지 않고 변하는 컴포넌트 즉,비제어 컴포넌트이다.
undefined 값이 들어올 때 발생할 수 있는 문제.

에러는 아니고 경고 수준이지만 컴포넌트가 렌더링 되었을 때 모든 경우에 대비하는 것이 중요하다고 생각했다.

해결법

값이 undefined일때 || 연산자 등으로 조건부 렌더링하기

profile
개발 공부한 걸 올립니다

0개의 댓글