Signature
instantsearch({ indexName: string, searchClient: object, // Optional parameters numberLocale: string, searchFunction: function, initialUiState: object, onStateChange: function, stalledSearchDelay: number, routing: boolean|object, insightsClient: function,});
Import
Copy
1
import instantsearch from 'instantsearch.js';
1
window.instantsearch
See code examples
About thiswidget
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:
indexName
: your search UI’s main indexsearchClient
: the search client for InstantSearch.js. 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 InstantSearch.js.
Middleware
InstantSearch.js 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 InstantSearch.js. For example, to send events to Google Analytics.
Examples
Copy
123456789101112
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 This option allows you to take control of search behavior. For example, to avoid doing searches at page load. When this option is set, A hook is called each time a search is requested (with Algolia’s helper API as a parameter). Carry out the search by calling helper.search(). When modifying the state of the helper within | ||||
Copy | |||||
initialUiState | type: object Optional Adds a uiState to your | ||||
Copy | |||||
onStateChange | type: function Optional 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 Optional 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 default: false Optional 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:
For more information, read the routing guide. | ||||
Copy | |||||
insightsClient | type: function Optional This function is 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. Use addWidgets([widget]) instead. | ||||
Copy | |||||
start | Finalizes the setup of 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. Use removeWidgets([widget]) instead. | ||||
Copy | |||||
dispose | Removes all widgets from the instance. This method doesn’t trigger a search. | ||||
Copy | |||||
setUiState | Injects a uiState into the instance without relying on internal events (such as connectors’ For this option to work, the widgets responsible for each UI state attribute need to be mounted. For instance, a searchBox is necessary to provide a | ||||
Copy | |||||
refresh | Clears the Algolia responses cache and triggers a new search. For more information, read the InstantSearch caching guide. | ||||
Copy |
Properties
status | type: "idle" | "loading" | "stalled" | "error" The status of the in-progress search. Possible values are:
| ||
Copy | |||
error | type: Error | undefined The error that occurred during the search. This is only defined when | ||
Copy | |||
renderState | type: RenderState | undefined The | ||
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 |