Creating an instance
InstantSearch requires a search client and an index name to initialize:Configuration options
The InstantSearch instance accepts several configuration options defined inInstantSearchOptions (from /home/daytona/workspace/source/packages/instantsearch.js/src/lib/InstantSearch.ts:62-195):
Required options
The search client to connect to your search backend. This must implement a
search method.The name of the main index. If no indexName is provided, you must manually add an index widget.
Optional options
Provides an initial state to widgets. The state is only used for the first search.
Enable URL routing to save UI state in the URL. Pass See the routing documentation for details.
true for default behavior or an object for custom configuration.Enable the Insights middleware to automatically send view and click events.
Time in milliseconds before a search is considered stalled.
Function called when the state changes. Using this makes the instance controlled.
Locale for formatting numbers, passed to
Number.prototype.toLocaleString().Feature flags for upcoming changes:
Instance methods
The InstantSearch instance exposes several methods (from/home/daytona/workspace/source/packages/instantsearch.js/src/lib/InstantSearch.ts:211-900):
Managing widgets
Adds widgets to the search instance. Widgets can be added before or after the instance has started.
Removes widgets from the search instance.
Lifecycle methods
Starts the InstantSearch instance and triggers the first search. This must be called after adding widgets.
Removes all widgets and stops the instance. The instance can be restarted later.
State management
Sets the UI state and triggers a search. Accepts a state object or a function.
Returns the current UI state.
Clears the cache and triggers a new search.
URL management
Creates a URL for the given state. Only available after
start() is called.Middleware
Adds middleware to the InstantSearch lifecycle.
Removes middleware from the instance.
Instance properties
The current status of the search.
The last error returned from the Search API. Cleared when the next valid response is received.
The main search helper instance. Available after
start() is called.The root index widget that contains all other widgets.
Events
InstantSearch extends EventEmitter and emits arender event after each search response:
Type signature
The InstantSearch class is generic and accepts type parameters for custom UI state:Related resources
Widgets
Learn about the widget system
Search state
Understanding UI state management
Routing
Synchronize state with URLs
Server-side rendering
Implement SSR with InstantSearch