Skip to content

[React] Formularios

José Bocanegra edited this page Mar 19, 2021 · 5 revisions

Formulario

Cree un nuevo componente denominado signup.js con el siguiente contenido:

function Signup() {
  return (
    <div>
      <form>
        <div>
          <label htmlFor="email">Email</label>
          <input
            type="email"
            id="email"
            name="email"
            autoComplete="password"
          />
        </div>

        <div>
          <label htmlFor="password">Password</label>
          <input
            type="password"
            id="password"
            name="password"
            autoComplete="password"
          />
        </div>

        <div>
          <label htmlFor="repeat_password">Confirm password</label>
          <input
            type="password"
            id="repeat_password"
            name="repeat_password"
            autoComplete="password"
          />
        </div>
        <button type="submit">Register</button>
      </form>
    </div>
  );
}

export default Signup;

Cree un hook para manejar el evento submit del formulario. Para esto, cree el archivo customHooks.js con el siguiente contenido:

const useSignUpForm = (schema) => {

  const handleSubmit = (event) => {
    event.preventDefault();
    console.log("Form submitted");
  };

  return { handleSubmit };
};

export default useSignUpForm;

Clone this wiki locally