<InstantSearch>
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.
<InstantSearch indexName={string} searchClient={object} // Optional props initialUiState={object} onStateChange={function} stalledSearchDelay={number} routing={boolean | object} insights={boolean | object} future={{ preserveSharedStateOnUnmount: boolean, persistHierarchicalRootCount: boolean, }} />
1
import { InstantSearch } from 'react-instantsearch';
About this widget
<InstantSearch>
is the root provider component of all widgets and Hooks.
You need two parameters:
indexName
: your search UI’s main indexsearchClient
: the search client for React InstantSearch. The search client needs anappId
and anapiKey
: find those credentials in your Algolia dashboard.
The getting started guide will help you get up and running with React InstantSearch.
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 functionality into React InstantSearch. For example, to send events to Google Analytics.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import React from 'react';
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch } from 'react-instantsearch';
const searchClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
function App() {
return (
<InstantSearch indexName="instant_search" searchClient={searchClient}>
{/* Widgets */}
</InstantSearch>
);
}
Props
Parameter | Description | ||
---|---|---|---|
indexName
|
type: string
Required
The main index in which to search. |
||
Copy
|
|||
searchClient
|
type: object
Required
Provides a search client to 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 |
||
Copy
|
|||
initialUiState
|
type: object
Provides an initial state to your React InstantSearch widgets using the Replace |
||
Copy
|
|||
onStateChange
|
type: function
Triggers when the state changes. This can be useful when performing custom logic on a state change. When using |
||
Copy
|
|||
stalledSearchDelay
|
type: number
default: 200
A time period (in ms) after which the search is considered to have stalled. Read the slow network guide for more information. |
||
Copy
|
|||
routing
|
type: boolean | object
The router configuration used to save the UI state into the URL or any client-side persistence. The object is accepted if it has either of these keys:
You can find more information in the routing guide. |
||
Copy
|
|||
insights
|
type: boolean | InsightsProps
default: false
Optional
Enables the Insights middleware and loads the To use this option with an object, refer to the Insights middleware options. |
||
Copy
|
|||
future
|
type: object
Optional
This option lets you try out new InstantSearch features without affecting the current experience for everyone else. See below for more information on individual future options. |
||
preserveSharedStateOnUnmount
|
since: v7.2.0
type: boolean
default: false
Optional
Changes the way If If |
||
Copy
|
|||
persistHierarchicalRootCount
|
since: v7.4.1
type: boolean
default: false
Optional
Whether to display a constant facet value count at the root of a hierarchical menu with active refinements. If If |
||
Copy
|