React
This is the React InstantSearch v7 documentation.
If you’re upgrading from v6, see the upgrade guide.
If you were using React InstantSearch Hooks,
this v7 documentation applies—just check for necessary changes.
To continue using v6, you can find the archived documentation.
<Autocomplete> widget to show suggestions.
When users select a suggestion, the widget navigates to the suggestion URL or refines the search query, depending on your configuration.
Open CodeSandbox
Run and edit the Query Suggestions UI example in CodeSandbox.
Explore source code
Browse the source code for the Query Suggestions UI example on GitHub.
This widget is and is subject to change in minor versions.
Add Query Suggestions and recent searches
The widget displays suggestions from a Query Suggestions index and recent searches stored in the browser’s local storage. Enable them with theshowQuerySuggestions and showRecent props:
React
Refine results with suggestions
To keep users on the same page, set up a multi-index search experience that uses the selected suggestion to search the main index. The<Autocomplete> widget targets the index that contains the suggestions.
The other widgets target the main index that contains your records.
For more information, see Multi-index search.
React
Customize recent searches
Pass an object toshowRecent to customize how each recent search renders:
React
Customize suggestions
Add anitemComponent to showQuerySuggestions to template each suggestion, and searchParameters to apply search parameters to the suggestions query:
React
<ReverseHighlight> to emphasize the text that doesn’t match the query.
This is a common style for Query Suggestions.
The widget has no built-in category grouping for suggestions and there’s no categoryAttribute.
To show a category next to a suggestion, render the category in the suggestion’s item template.
See also
- Autocomplete guide for the widget basics.