using react hooks form with react google autocomplete. Problem is on first selection, the react google autocomplete does not show the selected value, but just what the user types. Only if you select it the second time then it will say what you select. Subsequent selects are fine.
For example, user types in Disneyland and you select Disneyland Resort, Disneyland Drive, Anaheim, CA, USA from the autocomplete list, it still says Disneyland, but if you choose Disneyland Resort, Disneyland Drive, Anaheim, CA, USA again, it will now say that. anyone have any idea why this is happening and how to fix to get it to show the first time on select?
here is the code
import AutoComplete from "react-google-autocomplete";
import { useForm, Controller } from "react-hook-form";
const {
register,
handleSubmit,
control,
formState: { touchedFields, errors },
reset,
watch,
} = useForm();
<Controller
name="name"
control={control}
render={({ field, fieldState }) => (
<AutoComplete
apiKey={some_api_key}
options={{
types: ["establishment"],
fields: ["name"],
}}
{...field}
/>
)}
/>;
This worked for me:
onChangesends the value to the form's registry.Taken directly from the docs here.
Using react-hook-form: v 7.39.5
react-google-autocomplete: v 2.7.0