DocSearch component is the primary React component for integrating Algolia DocSearch into your application. It renders a search button and modal interface for searching documentation.
Import
Usage
Props
Algolia application ID used by the search client.
Public API key with search permissions for the index.
Name of the Algolia index to query.Deprecated: Use
indices property instead.List of indices and optional search parameters to be used for search.Each item can be a string (index name) or an object with:
name(string): Index namesearchParameters(SearchParamsObject): Optional search parameters for this index
Configuration or assistant ID to enable Ask AI mode. Pass a string assistant ID or a full config object.When provided as an object, supports:
assistantId(string, required): The assistant ID to useindexName(string): Index name for Ask AI (defaults to main index)apiKey(string): API key for Ask AI (defaults to main apiKey)appId(string): App ID for Ask AI (defaults to main appId)suggestedQuestions(boolean): Enable suggested questions displaysearchParameters(AskAiSearchParameters): Search parameters for AI context retrievalagentStudio(boolean): Experimental Agent Studio backend support
Intercept Ask AI requests (e.g., submitting a prompt or selecting a suggested question).Return
true to prevent the default modal Ask AI flow (no toggle, no sendMessage). Useful to route Ask AI into a different UI (e.g., @docsearch/sidepanel-js) without flicker.Theme overrides applied to the modal and related components.
Placeholder text for the search input.
Additional Algolia search parameters to merge into each query.Deprecated: Use
indices property instead.Maximum number of hits to display per source/group.
Hook to post-process hits before rendering. Receives an array of hits and should return the transformed array.
Custom component to render an individual hit.Signature:
(props: { hit: InternalDocSearchHit | StoredDocSearchHit; children: React.ReactNode }, helpers?: { html: (template: TemplateStringsArray, ...values: any[]) => any }) => JSX.ElementSupports multiple template patterns:- HTML strings with html helper:
(props, { html }) => html\…“ - JSX templates:
(props) => <div>...</div> - Function-based templates
Custom component rendered at the bottom of the results panel.Signature:
(props: { state: AutocompleteState<InternalDocSearchHit> }, helpers?: { html: (template: TemplateStringsArray, ...values: any[]) => any }) => JSX.Element | nullSupports the same template patterns as hitComponent.Hook to wrap or modify the Algolia search client. Use this to add custom headers, middleware, or other client modifications.
Disable storage and usage of recent and favorite searches.
Query string to prefill when opening the modal.
Custom navigator for controlling link navigation. Useful for client-side routing.
Localized strings for the button and modal UI.Object with optional properties:
button(ButtonTranslations): Button translationsmodal(ModalTranslations): Modal translations
Builds a URL to report missing results for a given query. The returned URL is used in the “no results” screen.
Insights client integration options to send analytics events.
The container element where the modal should be portaled to. Defaults to
document.body.Limit of how many recent searches should be saved/displayed.
Limit of how many recent searches should be saved/displayed when there are favorited searches.
Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.Object with optional properties:
'Ctrl/Cmd+K'(boolean): Enable/disable Ctrl/Cmd+K shortcut'/'(boolean): Enable/disable forward slash shortcut
Ref Methods
When usingReact.forwardRef, the component exposes a DocSearchRef object with methods for programmatic control:
Opens the search modal programmatically.
Closes the search modal programmatically.
