input value controlled 에러

김남경·2022년 11월 29일

react

목록 보기
7/37

ERROR
Warning: ... contains an input of type text with both value and defaultValue props. Input 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 input element and remove one of these props.

const [name, setName] = useState("");

//...
<input 
  defaultValue="a"
  value={name}
></input>

✅ input에서 defaultValue와 value를 함께 설정한 경우에 발생한 에러
✅ 둘 중 하나를 삭제해줌

profile
기본에 충실하며 앞으로 발전하는

0개의 댓글