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-plugin-query-suggestions
package to integrate them into the autocomplete menu.
This guide shows how to use Autocomplete to display a list of suggestions and their associated categories.
Once users select a suggestion, you will apply the query and the category using React InstantSearch.
To learn more, see:
- Integrate Autocomplete with React InstantSearch
- Integrate Autocomplete with React
- Build a Query Suggestions UI with Autocomplete
Refine your results with the suggestions
The first step is to set up an autocomplete component with Autocomplete. You can find more information in the guide on Using Autocomplete with React.React
autocomplete-plugin-query-suggestions
package provides the createQuerySuggestionsPlugin
function for creating a Query Suggestions plugin out-of-the-box. It requires the same Algolia search client used for your React InstantSearch app and an indexName
. The indexName
is the name of your Query Suggestions index.
To apply the suggestion, you can implement the useInstantSearch()
Hook. You also need to mount a <SearchBox>
widget or use its Hook to have React InstantSearch handle its state.
React
Use the related categories in the autocomplete
A typical use of autocomplete is to display both relevant categories and suggestions. Then when a user selects a suggestion, both the suggestion and the associated category are used to refine the search. For this example, the relevant categories are stored on the suggestions records. You must update your render function to display the categories with the suggestions. For simplicity and brevity of the code, assume that all suggestions have categories, but this isn’t the case in the actual dataset. Take a look at the complete example to see the actual implementation.React
Menu
widget or use its Hook,
then update the UI state with setIndexUiState
.
React