What is @docsearch/react?
@docsearch/react is a React component library that provides a search interface for documentation websites. It leverages Algolia's DocSearch to offer a fast and efficient search experience.
What are @docsearch/react's main functionalities?
Basic Search Implementation
This feature allows you to integrate a basic search interface into your React application. You need to provide your Algolia app ID, API key, and index name.
import { DocSearch } from '@docsearch/react';
function App() {
return (
<DocSearch
appId="YOUR_APP_ID"
apiKey="YOUR_API_KEY"
indexName="YOUR_INDEX_NAME"
/>
);
}
Customizing Search Box
This feature allows you to customize the search box, including placeholder text and button translations, to better fit the design and language of your application.
import { DocSearch } from '@docsearch/react';
function CustomSearch() {
return (
<DocSearch
appId="YOUR_APP_ID"
apiKey="YOUR_API_KEY"
indexName="YOUR_INDEX_NAME"
placeholder="Search documentation..."
translations={{
button: {
buttonText: 'Search',
buttonAriaLabel: 'Search'
}
}}
/>
);
}
Handling Search Events
This feature allows you to handle search events, such as input changes, to perform custom actions like logging the search query or triggering other functions.
import { DocSearch } from '@docsearch/react';
function SearchWithEvents() {
const handleSearchInput = (query) => {
console.log('Search query:', query);
};
return (
<DocSearch
appId="YOUR_APP_ID"
apiKey="YOUR_API_KEY"
indexName="YOUR_INDEX_NAME"
onInput={handleSearchInput}
/>
);
}
Other packages similar to @docsearch/react
react-instantsearch-dom
react-instantsearch-dom is a library by Algolia that provides a set of React components to build search interfaces. It offers more flexibility and customization options compared to @docsearch/react, but requires more setup and configuration.
react-searchbox
react-searchbox is a lightweight search component for React applications. It is simpler and easier to set up than @docsearch/react, but it does not offer the same level of integration with Algolia's search capabilities.
react-autosuggest
react-autosuggest is a React component for building input fields with suggestions. While it is not specifically designed for documentation search, it can be customized to provide similar functionality with more control over the suggestion logic.