@@ -7,7 +7,12 @@ import {
7
7
TextInput ,
8
8
View ,
9
9
} 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' ;
11
16
import { useState } from 'react' ;
12
17
13
18
const API_KEY = '<YOUR_API_KEY>' ;
@@ -43,13 +48,37 @@ export default function App() {
43
48
// Cancel previous request before sending a new one
44
49
if ( timeoutId ) clearTimeout ( timeoutId ) ;
45
50
46
- timeoutId = setTimeout ( async ( ) => {
51
+ // Debounce the request to avoid sending too many requests while the user is typing
52
+ timeoutId = setTimeout ( ( ) => {
47
53
try {
48
54
setIsLoading ( true ) ;
49
55
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 ) ;
53
82
} catch ( error ) {
54
83
setError ( error ) ;
55
84
} finally {
0 commit comments