Open gfox-dev opened 1 year ago
import usePlacesService from 'react-google-autocomplete/lib/usePlacesAutocompleteService';
import React, { ChangeEventHandler, useEffect } from 'react';
import TextField from 'components/Fields/TextField';
import useKYC from 'context/KYC';
import { PlaceDetails } from 'types';
const AutoCompletePlaces = () => {
const { setPlaceDetails } = useKYC();
const { placesService, placePredictions, getPlacePredictions } =
usePlacesService({
apiKey: process.env.NEXT_PUBLIC_GEO_API_KEY,
debounce: 100,
options: {
types: ['address'],
componentRestrictions: { country: 'us' },
},
});
useEffect(() => {
if (!placePredictions?.length || !placesService) return;
placesService.getDetails(
{ placeId: placePredictions[0].place_id },
(placeDetails: PlaceDetails) => setPlaceDetails(placeDetails)
);
}, [placePredictions]);
const handleChangeSearchField: ChangeEventHandler<HTMLInputElement> = (
event
) => {
getPlacePredictions({
input: event.target.value,
});
};
return (
<TextField
placeholder="Enter home address"
onChange={handleChangeSearchField}
/>
);
};
export default AutoCompletePlaces;
Triggers when value is changed.
Same, nobody has any update on this? Nothing works for me.