Skip to content

Commit 84781fe

Browse files
committed
feat: add debounceOptions
1 parent e563261 commit 84781fe

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ The `useGoogleAutocomplete` hook takes 2 arguments
2424

2525
# Config object
2626

27-
| Property | Description |
28-
| ------------ | ------------------------------------------------------------------------------------------------------ |
29-
| debounce | optional - default 300 |
30-
| language | optional - default 'en' |
31-
| queryTypes | optional - default address - https://developers.google.com/places/web-service/autocomplete#place_types |
32-
| minLength | optional - default 2 - this is the min length of the term search before start |
33-
| components | optional - A grouping of places to which you would like to restrict your results |
34-
| radius | optional - The distance (in meters) within which to return place results |
35-
| lat | optional - The latitude. If provided, lng is required |
36-
| lng | optional - The longitude. If provided, lat is required |
37-
| strictBounds | optional - Returns only places that are strictly within the region defined by location and radius. |
38-
| proxyUrl | optional - This is required if you want to use the hook in a Web based platform. Since we dont use the Google SDK, the http call will fail because of issues related to CORS unless a proxyUrl is provided |
27+
| Property | Description |
28+
| --------------- | ------------------------------------------------------------------------------------------------------ |
29+
| debounce | optional - default 300 |
30+
| debounceOptions | optional - Configuration options for debounce behavior. |
31+
| language | optional - default 'en' |
32+
| queryTypes | optional - default address - https://developers.google.com/places/web-service/autocomplete#place_types |
33+
| minLength | optional - default 2 - this is the min length of the term search before start |
34+
| components | optional - A grouping of places to which you would like to restrict your results |
35+
| radius | optional - The distance (in meters) within which to return place results |
36+
| lat | optional - The latitude. If provided, lng is required |
37+
| lng | optional - The longitude. If provided, lat is required |
38+
| strictBounds | optional - Returns only places that are strictly within the region defined by location and radius. |
39+
| proxyUrl | optional - This is required if you want to use the hook in a Web based platform. Since we dont use the Google SDK, the http call will fail because of issues related to CORS unless a proxyUrl is provided |
3940

4041
# Exposed properties
4142

src/GoogleAutocomplete.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ interface Options {
2020
*/
2121
debounce?: number;
2222

23+
/**
24+
* Debounce options
25+
*/
26+
debounceOptions?: {
27+
maxWait?: number;
28+
leading?: boolean;
29+
trailing?: boolean;
30+
equalityFn?: (left: any, right: any) => boolean;
31+
};
32+
2333
/**
2434
* Language for Google query - default: en
2535
*/
@@ -72,13 +82,14 @@ export const useGoogleAutocomplete = (apiKey: string, opts: Options = {}) => {
7282
const {
7383
minLength = 2,
7484
debounce = 300,
85+
debounceOptions = {},
7586
language = 'en',
7687
queryTypes = 'address',
7788
} = opts;
7889
const isMounted = useIsMounted();
7990
const [isSearching, setIsSearching] = useState(false);
8091
const [term, setTerm] = useState('');
81-
const [debouncedTerm] = useDebounce(term, debounce);
92+
const [debouncedTerm] = useDebounce(term, debounce, debounceOptions);
8293
const [locationResults, setLocationResults] = useState<
8394
GoogleLocationResult[]
8495
>([]);

0 commit comments

Comments
 (0)