Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@docsearch/react
Advanced tools
@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.
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}
/>
);
}
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 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 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.
React package for DocSearch, the best search experience for docs.
yarn add @docsearch/react@3
# or
npm install @docsearch/react@3
If you don’t want to use a package manager, you can use a standalone endpoint:
<script src="https://cdn.jsdelivr.net/npm/@docsearch/react@3"></script>
DocSearch generates a fully accessible search box for you.
import { DocSearch } from '@docsearch/react';
import '@docsearch/css';
function App() {
return (
<DocSearch
appId="YOUR_APP_ID"
indexName="YOUR_INDEX_NAME"
apiKey="YOUR_SEARCH_API_KEY"
/>
);
}
export default App;
FAQs
React package for DocSearch, the best search experience for docs.
The npm package @docsearch/react receives a total of 361,202 weekly downloads. As such, @docsearch/react popularity was classified as popular.
We found that @docsearch/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.