Skip to main content
This guide shows you how to build custom DocSearch integrations using the core packages. Whether you’re building for a new framework, a custom documentation platform, or need advanced customization, this guide covers the fundamentals.

Understanding DocSearch Packages

DocSearch is built as a modular system with several packages:

@docsearch/js

Vanilla JavaScript wrapper using Preact

@docsearch/react

React components and hooks

@docsearch/core

Framework-agnostic core logic

@docsearch/css

Styles and CSS variables

Architecture Overview

DocSearch is built on top of Algolia’s Autocomplete library:

Building a Framework Integration

Approach 1: Wrap the JavaScript Package

The simplest approach is to wrap @docsearch/js:
1

Install dependencies

2

Create a wrapper component

Example for Vue 3:
DocSearch.vue
3

Use the component

App.vue

Approach 2: Use React Components Directly

Many frameworks support React components. Example for Solid.js:
DocSearch.tsx

Approach 3: Build from Core

For complete control, use @docsearch/core directly:
custom-docsearch.ts

Custom Search Client

You can customize the Algolia search client:
custom-client.ts

Custom Result Transformations

Transform search results before rendering:

Custom Navigation

Control how DocSearch navigates:

Custom Hit Component

Customize how individual results are rendered:
Add a custom footer to the results:

TypeScript Integration

Create type-safe wrappers:
docsearch-wrapper.ts
Usage:

Server-Side Rendering

Handle SSR in your custom integration:
docsearch-ssr.ts

Analytics Integration

Track search usage:

A/B Testing

Implement A/B testing for search:

Testing Your Integration

Write tests for your custom integration:
docsearch.test.ts

Best Practices

Always clean up DocSearch instances when components unmount:
  • Lazy load DocSearch only when needed
  • Use the onTouchStart, onFocus, and onMouseOver callbacks to preload
  • Implement debouncing for search queries
Use TypeScript for better developer experience:
Handle errors gracefully:
Ensure your custom integration maintains accessibility:
  • Keep keyboard navigation working
  • Preserve ARIA attributes
  • Test with screen readers

Examples by Framework

Vue 3

See the Vue 3 example above for wrapping @docsearch/js

Svelte

Similar to Vue, use onMount and onDestroy lifecycle hooks

Angular

Create a directive or component that initializes DocSearch in ngAfterViewInit

Next.js

Use dynamic imports to avoid SSR issues

Next Steps

API Reference

Complete API documentation

Styling

Customize appearance

Core Package

Use @docsearch/core directly

Contributing

Contribute your integration