Custom Hit Component
ThehitComponent prop lets you render each search result with your own component.
Basic Custom Hit
Props Passed to hitComponent
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.Opening Links in New Tabs
To open search results in new tabs, combine a customhitComponent with the navigator prop:
Using the Default Children
If you want to keep the default hit content but add wrapper elements:Custom Results Footer Component
TheresultsFooterComponent allows you to render custom content at the bottom of the search results panel.
Basic Footer Component
Props Passed to resultsFooterComponent
state object contains:
state.query: Current search querystate.context.nbHits: Total number of resultsstate.collections: Array of result collectionsstate.status: Current search status (‘idle’, ‘loading’, ‘stalled’, ‘error’)
Advanced Footer Example
Conditional Footer Based on State
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.
