Form, Input

Hyemimi·2022년 12월 28일
0

TypeScript

목록 보기
4/9
post-thumbnail
import { useState } from "react";

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

 const onChange = (event: React.FormEvent<HTMLInputElement>)
  => {
    setValue(event.currentTarget.value);
  };
 const onSubmit = (event: React.FormEvent<HTMLFormElement>)
  => {
    event.preventDefault();
    console.log("hello", value);
  };
  return (
    <div>
      <form onSubmit={onSubmit}>
        <input
          value={value}
          onChange={onChange}
          type="text"
          placeholder="username"
        />
        <button>Log in</button>
      </form>
    </div>
  );
}

export default App;

event: React.FormEvent<HTMLInputElement>
event: React.FormEvent<HTMLFormElement>
에 주목하기. 나머지는 비슷

profile
암냠냠

0개의 댓글