diff --git a/src/google-places-autocomplete.tsx b/src/google-places-autocomplete.tsx index dfca1e7..b27306f 100644 --- a/src/google-places-autocomplete.tsx +++ b/src/google-places-autocomplete.tsx @@ -1,4 +1,4 @@ -import React, { forwardRef, useImperativeHandle } from 'react'; +import React, { forwardRef, useImperativeHandle, useCallback } from 'react'; import AsyncSelect from 'react-select/async'; import GooglePlacesAutocompleteProps, { GooglePlacesAutocompleteHandle } from './types'; @@ -24,6 +24,22 @@ const GooglePlacesAutocomplete: React.ForwardRefRenderFunction void) => { + const customSuggestions = args.customSuggestions || []; + + // Fetch Google Places suggestions + fetchSuggestions(inputValue, (googleSuggestions: any[]) => { + // Combine custom suggestions with Google suggestions + const combinedSuggestions = [ + ...customSuggestions, + ...googleSuggestions + ]; + + callback(combinedSuggestions); + }); + }, [fetchSuggestions, args.customSuggestions]); + useImperativeHandle(ref, () => ({ getSessionToken: () => { return sessionToken; @@ -36,7 +52,7 @@ const GooglePlacesAutocomplete: React.ForwardRefRenderFunction value.place_id} /> ); diff --git a/src/types.ts b/src/types.ts index 10626c1..7bb0980 100644 --- a/src/types.ts +++ b/src/types.ts @@ -35,4 +35,5 @@ export default interface GooglePlacesAutocompleteProps { onLoadFailed?: (error: Error) => void; selectProps?: AsyncProps>; withSessionToken?: boolean; + customSuggestions?: Array