nurbol.dev

nurbol.dev

Form data without refs

Creating FormData instance from submit events current target can give an access to form elements

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
  event.preventDefault();
  const data = new FormData(event.currentTarget);

  console.log({
    email: data.get('email'),
    password: data.get('password'),
  });
};