Skip to content

Commit 6653208

Browse files
committed
docs(examples): updated autosuggest options
1 parent 64e331a commit 6653208

File tree

1 file changed

+34
-5
lines changed
  • examples/react-native/autosuggest

1 file changed

+34
-5
lines changed

examples/react-native/autosuggest/App.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
TextInput,
88
View,
99
} from 'react-native';
10-
import { AutosuggestClient, AutosuggestSuggestion } from '@what3words/api';
10+
import {
11+
AutosuggestClient,
12+
AutosuggestInputType,
13+
type AutosuggestOptions,
14+
type AutosuggestSuggestion,
15+
} from '@what3words/api';
1116
import { useState } from 'react';
1217

1318
const API_KEY = '<YOUR_API_KEY>';
@@ -43,13 +48,37 @@ export default function App() {
4348
// Cancel previous request before sending a new one
4449
if (timeoutId) clearTimeout(timeoutId);
4550

46-
timeoutId = setTimeout(async () => {
51+
// Debounce the request to avoid sending too many requests while the user is typing
52+
timeoutId = setTimeout(() => {
4753
try {
4854
setIsLoading(true);
4955
setError(null);
50-
const options = { input: search };
51-
const { suggestions } = await client.run(options);
52-
setSuggestions(suggestions);
56+
const options: AutosuggestOptions = {
57+
input: search,
58+
inputType: AutosuggestInputType.Text,
59+
nResults: 3,
60+
// Uncomment the following options to restrict the search
61+
// focus: { lat: 51.521251, lng: -0.203586 },
62+
// clipToCountry: ['GB'],
63+
// clipToCircle: { center: { lat: 51.521, lng: -0.343 }, radius: 142 },
64+
// clipToBoundingBox: {
65+
// southwest: { lat: 51.521, lng: -0.343 },
66+
// northeast: { lat: 52.6, lng: 2.3324 },
67+
// },
68+
// clipToPolygon: [
69+
// { lat: 51.521, lng: -0.343 },
70+
// { lat: 52.6, lng: 2.3324 },
71+
// { lat: 54.234, lng: 8.343 },
72+
// { lat: 51.521, lng: -0.343 },
73+
// ],
74+
// language: 'en',
75+
// preferLand: true,
76+
};
77+
client
78+
.run(options)
79+
.then(({ suggestions }) => suggestions)
80+
.then(setSuggestions)
81+
.catch(console.error);
5382
} catch (error) {
5483
setError(error);
5584
} finally {

0 commit comments

Comments
 (0)