갈푸라떼
갈푸라떼는 개발중
갈푸라떼
전체 방문자
오늘
어제
  • 분류 전체보기 (232)
    • CS (0)
      • CSinfo (0)
    • Frontend (15)
      • HTML,CSS (1)
      • Javascript (2)
      • React (0)
      • React Hook (12)
    • Backend (0)
      • Python (0)
      • Node.js (0)
      • php (0)
    • DB (2)
      • MySQL (2)
      • BigQuery (0)
      • Mongodb (0)
    • Study (186)
      • JavaScript (72)
      • JavaScript(Clean code) (50)
      • Node.js (11)
      • HTML,CSS (13)
      • React (30)
      • TypeScript (10)
      • React-Native (0)
    • Error (2)
      • error (2)
    • Git (22)
      • Git (22)
    • Help Coding (4)
      • Useful websites (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • Github

공지사항

인기 글

태그

  • 네이밍
  • Arrow
  • SPREAD
  • function
  • 원시타입
  • 호이스팅
  • 프로토타입
  • 인터프리터
  • this
  • 실행 컨텍스트
  • class
  • 심볼
  • prototype
  • 함수
  • symbol
  • 오버라이딩
  • PM2
  • 객체타입
  • 상속
  • 컴파일러
  • 정적 레벨
  • Babel
  • 스코프 체인
  • 이터러블
  • 싱글스레드
  • structure
  • ECMAScript
  • 렉시컬 환경
  • 자바스크립트엔진
  • nodemon

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
갈푸라떼

갈푸라떼는 개발중

Study/TypeScript

[TypeScript] TypeScript & React SyntheticEvent(합성이벤트)

2022. 7. 22. 18:31

* [참고] https://ko.reactjs.org/docs/events.html

import React, { useState } from "react";
import "./App.css";

function App() {
  const [value, setValue] = useState("");

  const handleValue = (e: React.FormEvent<HTMLInputElement>) => {
    setValue(e.currentTarget.value);
  };

  const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {};
  
  const onClick = (e: React.MouseEvent<HTMLButtonElement>) => {};
  return (
    <div>
      <form onSubmit={onSubmit}>
        <input
          type="text"
          placeholder="username"
          value={value}
          onChange={handleValue}
        />
      </form>
      <button onClick={onClick}>Click</button>
    </div>
  );
}

export default App;
  • React.event이름.이벤트를 발생시키고 있는 Element 이름
  • form안에서 있는 input에서 event가 발생하고 있으므로 FormEvent<HTMLInputElement>로 type을 지정해준다.
  • form에서 event가 발생하고 있으므로 FormEvent<HTMLFormElement>로 type을 지정해준다.
  • button은 form안에서 동작하고 있지 않기 때문에 MouseEvent<HTMLButtonElement>로 type를 지정해준다.

'Study > TypeScript' 카테고리의 다른 글

[Typescript] call signature  (0) 2022.10.06
[TypeScript_study] type지정을 쉽게 하는 팁  (0) 2022.07.24
[TypeScript_study] Pick & Omit & Exclude & NonNullable  (0) 2022.07.05
[TypeScript_study] Record  (0) 2022.07.05
[TypeScript_study] 함수 오버로딩(Function Overloading)  (0) 2022.07.05
    'Study/TypeScript' 카테고리의 다른 글
    • [Typescript] call signature
    • [TypeScript_study] type지정을 쉽게 하는 팁
    • [TypeScript_study] Pick & Omit & Exclude & NonNullable
    • [TypeScript_study] Record
    갈푸라떼
    갈푸라떼

    티스토리툴바