Skip to main content
DocSearch provides a native React component that integrates seamlessly with React applications. The component is built with React hooks and supports React 16.8+.

Installation

Install the @docsearch/react package using your preferred package manager:
The package requires React >= 16.8.0 and React DOM >= 16.8.0 as peer dependencies.

CDN Installation

For quick prototyping, you can load DocSearch from a CDN:

Basic Setup

1

Import the DocSearch component

Import the DocSearch component and CSS styles:
2

Add DocSearch to your component

Render the DocSearch component with your Algolia credentials:
Don’t have your Algolia credentials yet? Apply to DocSearch to get started for free.

Complete Example

Here’s a complete example with typical configuration:
App.jsx

API Reference

DocSearch Component

The main React component for rendering DocSearch.

Props

string
required
Your Algolia application ID.
string
required
Your Algolia Search API key (public, search-only key).
string
The name of your Algolia index to search.
The indexName prop is deprecated. Use the indices prop instead for multi-index support.
Array<DocSearchIndex | string>
List of indices to search. Each item can be a string (index name) or an object with name and optional searchParameters.
string
Placeholder text for the search input. Defaults to “Search docs”.
SearchParamsObject
Additional Algolia search parameters to apply to all queries.
The searchParameters prop is deprecated. Use the indices prop with per-index parameters instead.
number
Maximum number of results to show per category. Defaults to 5.
(items: DocSearchHit[]) => DocSearchHit[]
Hook to transform search results before rendering.
React.Component
Custom component to render individual search results.
Custom component rendered at the bottom of the results panel.
(searchClient: DocSearchTransformClient) => DocSearchTransformClient
Hook to wrap or modify the Algolia search client.
object
Custom navigator for controlling link navigation. Useful for client-side routing.
boolean
Disable storage and display of recent and favorite searches. Defaults to false.
string
Query string to prefill when opening the search modal.
DocSearchTranslations
Localized strings for the button and modal UI.
({ query: string }) => string
Returns a URL to report missing results for a given query.
object
Algolia Insights client integration for analytics.
DocSearchTheme
Theme overrides for customizing the appearance.
DocumentFragment | Element
The container element where the modal should be portaled. Defaults to document.body.
DocSearchModalShortcuts
Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.
DocSearchAskAi | string
Configuration for Ask AI mode. Pass an assistant ID string or a full configuration object.

Using Refs

You can access DocSearch methods using a ref:

Ref Methods

() => void
Opens the search modal programmatically.
() => void
Closes the search modal programmatically.
(initialMessage?: InitialAskAiMessage) => void
Opens Ask AI mode with an optional pre-filled message.
boolean
Returns true if the modal is currently open.

Modular Components

DocSearch also exports individual components for advanced use cases:

DocSearchButton

The search button component without the modal:

DocSearchModal

The search modal component without the button:

useDocSearchKeyboardEvents

Hook for handling keyboard shortcuts:

TypeScript Support

DocSearch is written in TypeScript and includes full type definitions:

Styling

DocSearch comes with default styles. You can customize the appearance using:

CSS Variables

Theme Prop

Next Steps

Configuration

Learn about all available configuration options

Styling

Customize the appearance of your search

Ask AI

Enable AI-powered search assistance

API Reference

Explore the complete API documentation