리엑트 input value 오류

김윤진·2022년 3월 1일
0

문제해결

목록 보기
6/9

react_devtools_backend.js:4045 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.

react_devtools_backend.js:4045 경고: 구성 요소가 제어할 제어되지 않는 입력을 변경하고 있습니다. 이것은 값이 정의되지 않은 값에서 정의된 값으로 변경되기 때문에 발생할 수 있으며, 이는 발생해서는 안 됩니다. 구성 요소의 수명 동안 제어 또는 제어되지 않은 입력 요소를 사용할지 결정합니다.

const [todo, setTodo] = useState([]);

...

...
return (
  <input ... value={todo} />
)

input에 value에 undefined가 들어간 경우에 대한 처리가 없다는 오류

해결 방안

return (
  <input ... value={todo || ''} />
)```

0개의 댓글