Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- .env
- React Private Routes
- 모던 자바스크립트 Deep Dive
- 프로그래머스
- React
- React.memo
- next-auth
- React Router dom v6
- React Public Routes
- next.js
- BFS
- toast-ui-editor
- LV. 2
- react-dom
- Biweekly Contest 79
- 컴포넌트 최적화
- commitlint
- 모던 자바스크립티 Deep Dive
- Weekly Contest
- eslintrc
- Vite
- medinum
- Sanity.io
- 호이스팅
- Medium
- engines locking
- javascript
- leetcode
- sql
- tailwindcss
Archives
- Today
- Total
뚜벅
Warning: Use the `defaultValue` or `value` props on <select> instead of setting `selected` on <option> 해결 방법 본문
개발 관련
Warning: Use the `defaultValue` or `value` props on <select> instead of setting `selected` on <option> 해결 방법
초코맛젤리 2022. 8. 18. 05:30리액트 프로젝트 진행 중 select 태그를 사용하던 중 생긴 경고입니다.
<select name="" id="">
<option value="01" selected>서울특별시</option>
<option value="02">부산광역시</option>
<option value="03">대구광역시</option>
</select>
경고 내용은! 위의 코드처럼 option 안에서 selected를 사용하지 말고,
대신 select태그 안에서 defaultValue 또는 value를 사용하라고 말해 줍니다.
리액트 공식 문서에는 value를 사용하라고 나와 있습니다.
https://reactjs.org/docs/forms.html#the-select-tag
대신 value만 사용하게 될 경우 아래와 같은 경고문을 받습니다.
Warning: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`
그렇기 때문에 value를 사용할 경우 onChange를 추가해 주거나
defaultValue를 사용해 줍니다.
<select name="" id="" defaultValue="01">
<option value="01" selected>서울특별시</option>
<option value="02">부산광역시</option>
<option value="03">대구광역시</option>
</select>
++ value를 사용할 경우 onChange를 통해 변경해줄 수 있는 값을 사용해야 됩니다.
'개발 관련' 카테고리의 다른 글
Status code 422!! 에러 해결 (0) | 2022.10.10 |
---|---|
wsl2 에서 현재 폴더 위치 찾기 (0) | 2022.07.20 |