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

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

by 코딩하는 갓디노 2022. 1. 7.

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

 

react에서 select 태그 사용할때 
나오는 warning입니다.

 

Warning 오류 

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

 

before

 <select name="type" value={!adminRevData.type ? adminInfo.type : adminRevData.type}
 onChange={onChangeData}>
   <option>선택하세요</option>
   <option value="A">관리자</option>
   <option value="SA">최고 관리자</option>
 </select>

 

Warning 해결 방법

value="" 으로 빈 string 값을 넣어주었습니다.

 <select name="type" value={!adminRevData.type ? adminInfo.type : adminRevData.type}
 onChange={onChangeData}>
   <option value="">선택하세요</option>
   <option value="A">관리자</option>
   <option value="SA">최고 관리자</option>
 </select>

 

반응형

댓글