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 | 31 |
Tags
- JavaScript
- spread operation
- Hooks
- es11
- css #html
- HTML #CSS
- 프로그래머스
- Redux
- optional chanining
- react
- CSS
- Default parameter
- 카카오맵
- nextjs
- Python
- HTML
- 카카오맵 api
- Nullish Coalescing Operator
- es6
- Next
- React #Hooks
- React Kakao map
- Python #CodeUp
- firebase
- Python #Baekjoon
- Template literals
- BOJ
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