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.
Signature
Import
JavaScript
About this Hook
A React Hook that lets you access the InstantSearch API and interact with its state. UseuseInstantSearch to access and update UI state, retrieve search results, refresh the search, and add middleware.
Call this Hook from a component inside InstantSearch.
Examples
Parameters
boolean
default:false
If
true, InstantSearch catches errors during the search lifecycle and exposes them through the error property.
If you handle these errors elsewhere, set catchError to false.Returns
(indexUiState: IndexUiState) => void | ((prevIndexUiState: IndexUiState) => IndexUiState) => void
Updates the
uiState of the parent index..Accepts a new index UI state object or a function that receives the current index UI state and returns the next index UI state.Mount the widget that manages the UI state you update.
For example, mount a
RefinementList widget,
or an equivalent virtual widget,
for changes to refinementList to take effect.SearchResults
The search results.
UiState
The
uiState of the search interface.Each property maps an index identifier to that index’s UI state.
By default, the identifier is the index name.(uiState: UiState) => void | ((prevUiState: UiState) => UiState) => void
Function to update the
uiState of the search.This function either takes a new uiState object,
or a function that exposes the current uiState object and returns a new one.Mount the widget that manages the UI state you update.
For example, mount a
RefinementList widget,
or an equivalent virtual widget,
for changes to refinementList to take effect.ScopedResult[]
An array with the results of the index,
as well as the results of all adjacent
Index widgets.TypeScript
IndexRenderState
The
renderState of the parent index.RenderState
since: v7.2.0
The
renderState of the search.() => void
Clears the search client’s cache and performs a new search.This is useful to update the results once an indexing operation has finished.
(...middlewares: Middleware[]) => () => void
Adds one or more
middleware functions to InstantSearch.
Returns a cleanup function that removes them.JavaScript
idle | loading | stalled | error
The status of the search happening.Possible values are:
'idle': no search request is in progress.'loading': a search request is in progress. Use this status to provide immediate feedback after an action. For loading indicators, use'stalled'instead.'stalled': the search has exceededstalledSearchDelay.'error': the search failed. Theerrorproperty contains the search error.
Error | undefined
The error that occurred during the search.
This is only valid when
status is 'error'.