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 widget
<InstantSearch>
is the root wrapper component for all widgets and Hooks.
It takes two parameters:
indexName
. Your main search indexsearchClient
. The search client for React InstantSearch. The search client needs anappId
and anapiKey
, which you can find in the Algolia dashboard.
Middleware
React InstantSearch provides middleware to help you connect to other systems:- Insights. Use the
insights
middleware to send click and conversion events - Generic. With the
middleware
API, you can inject logic into React InstantSearch. For example, to send events to Google Analytics.
Examples
JavaScript
Props
The main index in which to search.
JavaScript
Provides a search client to
<InstantSearch>
.
Read the custom backend guidance on implementing a custom search client.The client uses a cache to avoid unnecessary search operations, so you should use a stable reference to the same search client instance rather than creating a new one on each render. Avoid inlining the function call to algoliasearch
as the prop value, and consider instantiating the client outside your React components.JavaScript
Provides an initial state to your React InstantSearch widgets using the
ui-state
object from InstantSearch.js.Since this sets the initial state for your UI,
you need to include the corresponding widgets in your app.
For example, page: 5
as initial state only has an effect
if you include the pagination
widget as well.Replace YourIndexName
with the name of your Algolia index.JavaScript
Triggered when the state changes.
This can be helpful for performing custom logic on a state change.When using
onStateChange
, the instance is under your control. You’re responsible for updating the UI state (with setUiState
).A time period (in ms) after which the search is considered to have stalled.
Read the slow network guide for more information.
JavaScript
The router configuration used to save the UI state into the URL or any client-side persistence.For more information, see Sync your URLs.You can’t use
initialUiState
with routing as the two options override each other.- Use
initialUiState
for simple and static use cases - Use
routing
for anything complex or dynamic.
JavaScript
Enables the Insights middleware and loads the
search-insights
library (if not already loaded). The Insights middleware sends view and click events automatically, and lets you set up your own click and conversion events.To use this option with an object, refer to the Insights middleware options.Test new InstantSearch features without affecting others.