useSuggestions
Suggests places for text as it is typed, over the services' optional
SuggestionProvider. Returns the suggestions for the latest text that has
settled, or none.
This is a function exported by @mapcairn/map, checked against version 0.2.0.
Signature
import { useSuggestions } from "@mapcairn/map";
function useSuggestions(query: string, enabled: boolean): readonly SearchResult[];
Description
A request starts only when the trimmed text has been unchanged for
SUGGEST_DEBOUNCE_MS, is at least MIN_SUGGEST_LENGTH
characters and has a word in it, so a coordinate pair typed digit by digit
is never sent (the search itself answers a whole pair without a service).
Each change of text aborts the request before it, so an
answer for older text never arrives after a newer one. Nothing is asked
while enabled is false, which a caller uses after the person has picked
a suggestion so the box showing its label does not suggest again.
When the service fails the person is not interrupted: no suggestions show,
and Enter still searches. After SUGGEST_FAILURE_LIMIT failures in a
row, or one rate-limited answer, it stops asking for
SUGGEST_COOLDOWN_MS and announces once that suggestions are
unavailable and Enter still works. It announces again only after a request
has worked in between. A host without a provider gets no suggestions and no
announcements.
Counts go out through the app-wide announcer, politely.
Parameters
query(string)enabled(boolean)
Returns
readonly SearchResult[]
See also
Source: packages/map/src/tools/SearchPill/useSuggestions.ts:61