# 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

```ts
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`](https://docs.mapcairn.com/api/map/SUGGEST_DEBOUNCE_MS.md), is at least [`MIN_SUGGEST_LENGTH`](https://docs.mapcairn.com/api/map/MIN_SUGGEST_LENGTH.md)
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`](https://docs.mapcairn.com/api/map/SUGGEST_FAILURE_LIMIT.md) failures in a
row, or one `rate-limited` answer, it stops asking for
[`SUGGEST_COOLDOWN_MS`](https://docs.mapcairn.com/api/map/SUGGEST_COOLDOWN_MS.md) 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

- [`SearchResult`](https://docs.mapcairn.com/api/core/SearchResult.md)

Source: [packages/map/src/tools/SearchPill/useSuggestions.ts:61](https://github.com/MapCairn/mapcairn/blob/main/packages/map/src/tools/SearchPill/useSuggestions.ts#L61)
