Skip to content

Commit

Permalink
Revert the placeSelect related change
Browse files Browse the repository at this point in the history
  • Loading branch information
hovsepyan021 committed Sep 10, 2024
1 parent e0b83c4 commit 76af65c
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export const GeoapifyGeocoderAutocomplete = ({
const apiKey = React.useContext<string>(GeoapifyApiKey);
let geocoderContainer: HTMLDivElement | null;

let initialized = false;

const geocoderAutocomplete: MutableRefObject<
GeocoderAutocomplete | undefined
> = useRef<GeocoderAutocomplete>();
Expand Down Expand Up @@ -157,43 +159,43 @@ export const GeoapifyGeocoderAutocomplete = ({
},[]);

useEffect(() => {
if (!geocoderAutocomplete.current) {
geocoderAutocomplete.current = new GeocoderAutocomplete(
geocoderContainer as HTMLDivElement,
apiKey,
{
placeholder: placeholderValue || "",
addDetails: addDetailsValue,
skipIcons: skipIconsValue,
skipSelectionOnArrowKey: skipSelectionOnArrowKeyValue,
allowNonVerifiedHouseNumber: allowNonVerifiedHouseNumberValue,
allowNonVerifiedStreet: allowNonVerifiedStreetValue,
debounceDelay: debounceDelayValue || 100,
}
);

geocoderAutocomplete.current.on("select", onSelect);
geocoderAutocomplete.current.on("suggestions", onSuggestions);
geocoderAutocomplete.current.on("input", onUserInput);
geocoderAutocomplete.current.on("close", onClose);
geocoderAutocomplete.current.on("open", onOpen);
}

if (sendGeocoderRequestFuncValue) {
geocoderAutocomplete.current.setSendGeocoderRequestFunc(
sendGeocoderRequestFuncValue
);
}

return () => {
if (initialized) {
if (geocoderAutocomplete.current) {
geocoderAutocomplete.current.off("select", onSelect);
geocoderAutocomplete.current.off("suggestions", onSuggestions);
geocoderAutocomplete.current.off("input", onUserInput);
geocoderAutocomplete.current.off("close", onClose);
geocoderAutocomplete.current.off("open", onOpen);
}
};

return;
}

initialized = true;

geocoderAutocomplete.current = new GeocoderAutocomplete(
geocoderContainer as HTMLDivElement,
apiKey,
{
placeholder: placeholderValue || "",
addDetails: addDetailsValue,
skipIcons: skipIconsValue,
skipSelectionOnArrowKey: skipSelectionOnArrowKeyValue,
allowNonVerifiedHouseNumber: allowNonVerifiedHouseNumberValue,
allowNonVerifiedStreet: allowNonVerifiedStreetValue,
debounceDelay: debounceDelayValue || 100
}
);

geocoderAutocomplete.current.on("select", onSelect);
geocoderAutocomplete.current.on("suggestions", onSuggestions);
geocoderAutocomplete.current.on("input", onUserInput);
geocoderAutocomplete.current.on("close", onClose);
geocoderAutocomplete.current.on("open", onOpen);

if (sendGeocoderRequestFuncValue) {
geocoderAutocomplete.current.setSendGeocoderRequestFunc(sendGeocoderRequestFuncValue)
}
}, []);

useEffect(() => {
Expand Down

0 comments on commit 76af65c

Please sign in to comment.