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 |
Tags
- JavaScript
- Python #CodeUp
- 프로그래머스
- CSS
- firebase
- Next
- Python
- Template literals
- Python #Baekjoon
- optional chanining
- react
- HTML #CSS
- 카카오맵
- HTML
- nextjs
- es11
- Default parameter
- 카카오맵 api
- Hooks
- css #html
- Redux
- BOJ
- es6
- React Kakao map
- Nullish Coalescing Operator
- spread operation
- React #Hooks
Archives
- Today
- Total
거북이개발자
[ReactHooks] 첨부파일 초기화 본문
1. 배경

위와 같이 파일을 첨부했을시 다시 초기화 하고 싶을때가 있다.
2. 배경
const fileInput=useRef();
const onClearAttachment=()=>{
fileInput.current.value = "";
};
<input type="file" accept="image/*" ref={fileInput} onChange={onImgChange} />
위의 코드처럼 useRef를사용해준다. 그후 fileInput.current.value=""을 이용해 초기화 해줄 수 있다.
중요한점음 input 태그에서 어트리뷰트로 ref를 넣어줘야 한다.
'React > ReactHooks' 카테고리의 다른 글
| [ReactHooks] lifecycle, useEffect (0) | 2021.01.22 |
|---|---|
| [ReactHooks] useRef, Time함수, 3항연산자, 렌더링 (0) | 2021.01.20 |
| [ReactHooks] useState, 함수형 (2) | 2021.01.18 |
Comments