Skip to main content
DocSearch allows you to replace the default hit and footer rendering with custom React components, giving you complete control over how search results appear.

Custom Hit Component

The hitComponent prop lets you render each search result with your own component.

Basic Custom Hit

Props Passed to hitComponent

The children prop contains the default DocSearch hit content structure. You can:
  • Wrap it in a custom container
  • Replace it entirely with your own markup
  • Add additional elements around it

Complete Custom Hit Example

Here’s a fully customized hit that replaces the default content:
When you access hit properties like _snippetResult or _highlightResult, you get the highlighted/snippeted version from Algolia with HTML markup. Use dangerouslySetInnerHTML to render it.
To open search results in new tabs, combine a custom hitComponent with the navigator prop:
Using target="_blank" in the hitComponent alone only works for mouse clicks. Keyboard navigation (arrow keys + Enter) requires the navigator prop to open links in new tabs consistently.

Using the Default Children

If you want to keep the default hit content but add wrapper elements:
The resultsFooterComponent allows you to render custom content at the bottom of the search results panel.

Props Passed to resultsFooterComponent

The state object contains:
  • state.query: Current search query
  • state.context.nbHits: Total number of results
  • state.collections: Array of result collections
  • state.status: Current search status (‘idle’, ‘loading’, ‘stalled’, ‘error’)

TypeScript Support

When using TypeScript, you can import the proper types:

Styling Tips

CSS Classes

The default DocSearch structure uses classes like DocSearch-Hit, DocSearch-Hit-Container, etc. You can target these in your custom components or replace them entirely.

Theme Integration

Use inline styles or CSS classes that match your site’s design system. The theme prop controls modal colors but doesn’t affect custom component styles.

Responsive Design

Ensure your custom components work well on mobile devices where the modal is full-screen.

Complete Example