You are viewing the documentation for InstantSearch.js v4.
To upgrade from v3, see the migration guide.
Looking for the v3 version of this page?
View the v3 docs.
About this widget
connectAutocomplete
is a connector.
It creates a connected component that provides access to all indices of your InstantSearch instance.
-
To configure the number of hits you show,
use either the
hitsPerPage
or theconfigure
widget. -
To retrieve results from multiple indices,
use the
index
widget.
The Autocomplete UI library lets you build a full-featured, accessible search experience.
For more information, see Integrate Autocomplete with InstantSearch.js.
Customize the UI with connectAutocomplete
If you want to create your own UI of the autocomplete
widget, you can use connectors.
To use connectAutocomplete
, you can import it with the declaration relevant to how you installed InstantSearch.js.
JavaScript
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
JavaScript
Rendering options
The indices this widget has access to.
You can leverage the highlighting feature of Algolia through the
highlight
function,
directly from the connector’s render function.
Each index
widget is provided with:indexName: string
. The name of the index (can change withsortBy
).indexId: string
. The identifier of this index object.hits: object[]
. The resolved hits from the index matching the query.results: object
. The full results object from the Algolia API.sendEvent: function
. A function to sendclick
orconversion
events. Theview
event is automatically sent when the connector renders hits. For more information, see theinsights
middleware.
JavaScript
The current value of the query.
JavaScript
Searches into the indices with the provided query.
JavaScript
All original widget options forwarded to the render function.
JavaScript
Create and instantiate the custom widget
First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:- Instance parameters. Predefined options that configure Algolia’s behavior.
- Custom parameters. Parameters you define to make the widget reusable and adaptable.
renderFunction
, both instance and custom parameters are accessible through connector.widgetParams
.
JavaScript
Instance options
Escapes HTML entities from hits string values.
JavaScript