useSuggest
The useSuggest hook provides typeahead suggestions and document preview results as a user enters a search phrase. It's ideal for building autocomplete and "search-as-you-type" experiences. The hook is only available in versions 2.4.0 and above.
Configuration
To use the hook, you can provide the searchIndexId and the partial search phrase as query.
Supported parameters
The hook supports the following options:
Parameter | Type | Description |
|---|---|---|
| string | The ID of the SitecoreAI search index to retrieve results from. Required |
| string | Partial text used for typeahead suggestions. It is trimmed before the request is sent and mapped to the |
| string | Specify the locale for the request. Required for multi-locale index configurations (for example, |
| boolean | Specify whether the request runs automatically. Defaults to |
| boolean | Specify whether the previous suggestions and previews should be kept while fetching a new query. Defaults to |
The hook does not send a request when query is omitted or contains only whitespace. Use enabled: false when the request should not run automatically.
The returned state includes querySuggestions, previewResults, status, error, and the loading flags isLoading, isSuccess, and isError. When keepPreviousData is enabled, isPreviousData indicates that the returned results belong to the previous query while the new request is loading.