본문 바로가기
💻CODING/react. vue

[react] Warning: `value` prop on `input` should not be null.

by 코딩하는 갓디노 2022. 2. 8.

[react] Warning: `value` prop on `input` should not be null.

 

react로 form 작업할 때 자주 나타나게 되는 warning 이에요.

 

Warning 오류 

Warning: `value` prop on `input` should not be null.
Consider using an empty string to clear the component or `undefined` for uncontrolled components.

 

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


before

<input type="number" name={'weight'} value={data.weight} />

 

after

 

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



 

 

반응형

댓글