[에러] Select elements must be either controlled or uncontrolled.

옥수수의 코딩이야기·2023년 2월 5일
0

에러

목록 보기
3/18
post-thumbnail
import Selector from "../common/Selector";
        <Selector
          type="register"
          disabled={!largeBuildingType}
          value={buildingType || undefined}
          defaultValue="하나를 선택해주세요"
          disabledOptions={disabledlargeBuildingTypeOptions}
          label="건물 유형을 선택하세요."
          options={detailBuildingOptions}
          isValid={!!buildingType}
          onChange={onChangeBuildingType}
        />

(Seletcor은 select태그를 사용하고 있음)

문제: select 사용시 에러문구 발생
Select elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both). Decide between using a controlled or uncontrolled select element and remove one of these props.
이유: Select elements는 컨트롤 되거나 안되게 둘중 하나만 하라는 건데..
value prop와 defaultValue prop는 같이 사용할 수 없다고 한다
해결방안: defaultValue prop을 삭제하자

참고
https://chinsun9.github.io/2020/12/07/Select-elements-must-be-either-controlled-or-uncontrolled/

profile
프론트엔드 공부중 기억은 블로그가 대신합니다.

0개의 댓글