instantsearch
instantsearch({ indexName: string, searchClient: object, // Optional parameters numberLocale: string, searchFunction: function, initialUiState: object, onStateChange: function, stalledSearchDelay: number, routing: boolean|object, insightsClient: function, });
About this widget
You are currently reading the documentation for InstantSearch.js V4. Read our migration guide to learn how to upgrade from V3 to V4. You can still access the V3 documentation for this page.
The instantsearch
object is the main component of InstantSearch.js. It manages the widget and lets you add new ones.
Two parameters are required to get you started with InstantSearch.js:
indexName
: the main index that you need to use for your new search UIsearchClient
: the search client to plug to InstantSearch.js
The search client provided by Algolia needs an appId
and an apiKey
. Those parameters can be found in your Algolia dashboard.
To get up and running quickly with InstantSearch.js, have a look at the getting started guide.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
const search = instantsearch({
indexName: 'instant_search',
searchClient: algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
),
});
// Add widgets
// ...
search.start();
Options
indexName
|
type: string
Required
The main index to search into. |
||
Copy
|
|||
searchClient
|
type: object
Required
Provides a search client to |
||
Copy
|
|||
numberLocale
|
type: string
Optional
The locale used to display numbers. This is passed to |
||
Copy
|
|||
searchFunction
|
type: function
Optional
A hook that is called each time a search needs to be done, with the helper as a parameter.
It’s your responsibility to call When modifying the state of the helper within |
||
Copy
|
|||
initialUiState
|
type: object
Optional
Adds a |
||
Copy
|
|||
onStateChange
|
type: function
Optional
Triggers when the state changes. Whenever you start using this option, the instance becomes controlled. This means that you become responsible for updating the UI state with This can be useful to perform custom logic whenever the state changes. |
||
Copy
|
|||
stalledSearchDelay
|
type: number
default: 200
Optional
Defines a time period after which a search is considered stalled. You can find more information in the slow network guide. |
||
Copy
|
|||
routing
|
type: boolean|object
default: false
Optional
The router configuration used to save the UI state into the URL, or any client-side persistence. You can find more information in the routing guide. The object form accepts two attributes:
|
||
Copy
|
|||
insightsClient
|
type: function
Optional
The function exposed by the |
||
Copy
|
Methods
addWidgets
|
Adds widgets to the You can add widgets to |
||
Copy
|
|||
addWidget
|
Adds a widget to the You can add widgets to This method is deprecated and is only supported until 4.x releases. Please use |
||
Copy
|
|||
start
|
Finalizes the setup of You should call this method after you have added all your required widgets to |
||
Copy
|
|||
removeWidgets
|
Removes widgets from the The widgets you remove from |
||
Copy
|
|||
removeWidget
|
Removes a widget from the The widget you remove from This method is deprecated and is only supported until 4.x releases. Please use |
||
Copy
|
|||
dispose
|
Removes all widgets from the instance. This methods doesn’t trigger a search. |
||
Copy
|
|||
setUiState
|
Injects a For the UI state to work, the widgets responsible for each UI state attribute need to be mounted. For instance, a |
||
Copy
|
|||
refresh
|
Clears the Algolia responses cache and triggers a new search. You can find more details about caching in InstantSearch in our guide about caching. |
||
Copy
|
Events
render
|
Fires when all widgets are rendered. This happens after every search request. |
||
Copy
|
|||
error
|
Fires when calling the API reports an error. |
||
Copy
|