티스토리 뷰
반응형
마우스 클릭 시 type 지정하여, event 값을 가져오는 데 어려움을 겪는 사람들을 위해 글을 적어보겠다.
보통 에러가 나는 부분은 event를 가지고와서 핸들링할 때, 주로 발생을 한다. event.target as HTMLElement 를 활용해서 사용하는 방식을 사용하면 된다. 사실 간단히 아래와 같이 구현이 가능하다.
type CustomMouseEvent = MouseEvent<HTMLElement>;
const TestComponent = () => {
const handleSelect = (event: CustomMouseEvent) => {
const eventTarget = event.target as HTMLElement;
console.log(eventTarget.innerTest)
};
return (
<button
onClick={TestComponent}
>
Click Here!
</button>
)
}
위의 예제를 활용해서 응용을 진행해 보자.
반응형
'Web > typescript' 카테고리의 다른 글
[typescript] assert 로 타입 보장하기 (0) | 2023.01.30 |
---|
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- BFS
- DFS
- useState
- 자연어처리
- mongoDB
- nodejs
- Queue
- typescript
- 클라우데라
- Deque
- 자료구조
- TensorFlow
- error:0308010C:digital envelope routines::unsupported
- NextJS
- login
- next.config.js
- JavaScript
- django
- Vue
- UserCreationForm
- Express
- Python
- logout
- vuejs
- pandas
- read_csv
- react autoFocus
- react
- useHistory 안됨
- nextjs autoFocus
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함