useAutocomplete()
This is the React InstantSearch v7 documentation. React InstantSearch v7 is the latest version of React InstantSearch and the stable version of React InstantSearch Hooks.
If you were using React InstantSearch v6, you can upgrade to v7.
If you were using React InstantSearch Hooks, you can still use the React InstantSearch v7 documentation, but you should check the upgrade guide for necessary changes.
If you want to keep using React InstantSearch v6, you can find the archived documentation.
About this Hook
This Hook provides access to all indices of your InstantSearch instance.
The useAutocomplete
Hook isn’t available in React InstantSearch, but you can make a custom version with useConnector()
and connectAutocomplete
.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { useConnector } from 'react-instantsearch';
import connectAutocomplete from 'instantsearch.js/es/connectors/autocomplete/connectAutocomplete';
// Connect the InstantSearch.js `connectAutocomplete` connector to your component
export function useAutocomplete(props) {
return useConnector(connectAutocomplete, props);
}
// The props you can use in your component to interact with Autocomplete
export function Autocomplete(props) {
const { indices, currentRefinement, refine } = useAutocomplete(props);
return <>{/* Your JSX */}</>;
}