[React] Input 태그 속성 value & defaultValue
에러 내용
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
.
문제 코드
- 상태에 따라 input value가 변화함
<FilterInput value={getFilterBarString(filterBarInput)}></FilterInput>
- getFilterBarString는 filterBarInput이라는 상태를 받아 string을 리턴해주는 함수이다.
const getFilterBarString = () => {
return Object.entries(filterBarInput).reduce((acc, item) => {
if (item[1]) {
if (item[0] === "placeholder") acc += `${item[1]} `;
else acc += `${item[0]}:${item[1]} `;
}
return acc;
}, "");
};
Author And Source
이 문제에 관하여([React] Input 태그 속성 value & defaultValue), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dami/React-Input-태그-속성-value-defaultValue저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)