단순 코드 기록/React

React_등록(FormData)

일일일코_장민기 2024. 3. 22. 12:45
728x90
export default function Login() {

  function handleSubmit(event){
    event.preventDefault();
    const fd = new FormData(event.target);
    const email = fd.get("email");
    const password = fd.get("password");
    const address = fd.get("address");
    console.log(email, password, address)
  }

  return (
    <>
      <h2>Signup</h2>
      <form onSubmit={handleSubmit}>
        <div>
          <div>
            <label htmlFor="email">Email</label>
            <input id="email" name="email" type="email"></input>
          </div>
        </div>
        <div>
          <div>
            <label htmlFor="password">password</label>
            <input id="password" name="password" type="password"></input>
          </div>
        </div>
        <div>
          <div>
            <label htmlFor="address">address</label>
            <input id="address" name="address" type="text"></input>
          </div>
        </div>
        <div>
          <div>
            <label htmlFor="address2">address2</label>
            <input id="address2" name="address2" type="text"></input>
          </div>
        </div>
        <p>
          <button>Login</button>
        </p>
      </form>
    </>
  );
}