Hooks
useSearchSuggestions
const { suggestions, isLoading, error } = useSearchSuggestions(query, options)Get ranked place suggestions as the user types. The hook debounces requests and clears stale matches when the query changes.
Parameters
query(string): The current input text. The hook trims surrounding whitespace and searches only when the trimmed text is 2–100 characters long.options(optional): Settings for the search request. See Options.
Return Values
Prop
Type
Options
Prop
Type
Example
import { useSearchSuggestions, type SearchSuggestion } from '@mapquest/sdk'
import { useState } from 'react'
import { ActivityIndicator, Button, Text, TextInput, View } from 'react-native'
export function PlaceSearch({ onSelect }: { onSelect: (place: SearchSuggestion) => void }) {
const [query, setQuery] = useState('')
const { suggestions, isLoading, error } = useSearchSuggestions(query)
return (
<View>
<TextInput value={query} onChangeText={setQuery} placeholder="Search for a place" />
{isLoading && <ActivityIndicator />}
{error && <Text>Couldn't load suggestions. Try editing your search.</Text>}
{suggestions.map(place => (
<Button key={place.id} title={place.displayString} onPress={() => onSelect(place)} />
))}
</View>
)
}Only show a “no matches” message after an eligible search finishes without an error. When a user selects a suggestion, check place.place before centering a map: a category or franchise need not identify a single location.
Search with or without location
You can offer search before asking for location permission. If a position is available, the hook favors nearby matches; otherwise it still returns suggestions. Mounting the search subscribes to location updates even if the input is empty, but movement alone does not repeat a search.