Answers for "Autocomplete an Address with a React hook Form"

0

Autocomplete an Address with a React hook Form

import React from "react";
import { useForm } from "react-hook-form";

export default function App() {
  const { register, handleSubmit, errors } = useForm();
  const onSubmit = data => console.log(data);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input
        type="text"
        aria-invalid={errors.firstName ? "true" : "false"}
        name="firstName"
        ref={register({ required: true })}
      />
      { errors.firstName && (
          <span role="alert">
            This field is required
          </span>
        )
      }

      <input type="submit" />
    </form>
  );
}
Posted by: Guest on July-31-2020

Code answers related to "Autocomplete an Address with a React hook Form"

Code answers related to "Javascript"

Browse Popular Code Answers by Language