티스토리 뷰
input값을 넘긴 후 input값을 초기화하려고 하는데 오류가 남!
class addForm extends Component {
inputRef = createRef();
addHabit = (e) => {
e.preventDefault();
const name = this.inputRef.current.value;
this.props.addHabit(name);
this.inputRef.current.reset();
};
......
this.inputRef.current.reset is not a function
this.inputRef.current.reset는 함수가 아니다
왜..? reset()은 있는 건데... 왜...?
input에는 reset()을 사용할 수 없다
input을 감싸고 있는 form에 reset()을 해줘야함
class addForm extends Component {
inputRef = createRef();
formRef = createRef();
addHabit = (e) => {
e.preventDefault();
const name = this.inputRef.current.value;
this.props.addHabit(name);
this.formRef.current.reset();
};
참고
https://stackoverflow.com/questions/62412963/how-to-reset-input-field-from-useref-in-react
How to reset input field from useRef in React?
I have a text input. If I click on a specific button in the page, I want to reset the value of the input. Here is my code: const inputRef = useRef() const handleClick= () => { inputRef.
stackoverflow.com
728x90
'에러 노트' 카테고리의 다른 글
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 코드잇
- 자바스크립트
- Til
- 김버그
- git
- Python
- vscode
- 스파르타코딩클럽
- javascript
- 제이쿼리
- html
- 깃
- React
- 비주얼스튜디오코드
- 리액트
- 파이썬
- TS
- 코딩앙마
- Typescript
- 타입스크립트
- 저스트코드
- js
- vue
- scss
- 구름에듀
- 드림코딩
- map
- CSS
- 회고
- 제로초
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함