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.
@algolia/autocomplete-preset-algolia
Advanced tools
Presets for building autocomplete experiences with Algolia.
@algolia/autocomplete-preset-algolia is a preset for Algolia's Autocomplete library that provides a set of default configurations and sources to quickly set up an autocomplete experience with Algolia's search capabilities.
Basic Autocomplete Setup
This code sets up a basic autocomplete experience using Algolia's search client and the preset provided by @algolia/autocomplete-preset-algolia. It initializes the autocomplete with a container and the necessary search client and index name.
const { autocomplete } = require('@algolia/autocomplete-js');
const { createAlgoliaPreset } = require('@algolia/autocomplete-preset-algolia');
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
autocomplete({
container: '#autocomplete',
presets: [
createAlgoliaPreset({
searchClient,
indexName: 'your_index_name',
}),
],
});
Customizing Autocomplete Sources
This code demonstrates how to customize the sources for the autocomplete. It uses the `getSources` function to define a custom source that queries the Algolia index and returns items based on the search query.
const { autocomplete } = require('@algolia/autocomplete-js');
const { createAlgoliaPreset } = require('@algolia/autocomplete-preset-algolia');
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
autocomplete({
container: '#autocomplete',
presets: [
createAlgoliaPreset({
searchClient,
indexName: 'your_index_name',
getSources({ query }) {
return [
{
sourceId: 'products',
getItems() {
return searchClient.search([{ indexName: 'your_index_name', query }]);
},
templates: {
item({ item }) {
return `<div>${item.name}</div>`;
},
},
},
];
},
}),
],
});
react-autosuggest is a React component for building autocomplete and autosuggest functionality. It is highly customizable and can be used with any data source. Unlike @algolia/autocomplete-preset-algolia, it does not come with built-in support for Algolia's search client.
downshift is a library that provides primitives to build flexible autocomplete, combobox, dropdown, and select components in React. It offers more control over the rendering and behavior of the components compared to @algolia/autocomplete-preset-algolia, which is more opinionated and tailored for Algolia's search.
autocomplete.js is a JavaScript library for building autocomplete experiences. It is highly customizable and can be integrated with various data sources, including Algolia. However, it requires more manual setup compared to @algolia/autocomplete-preset-algolia, which provides a preset configuration for Algolia's search.
The Algolia preset provides fetching and highlighting utilities for usage with Algolia.
yarn add @algolia/autocomplete-preset-algolia
# or
npm install @algolia/autocomplete-preset-algolia
See Documentation.
FAQs
Presets for building autocomplete experiences with Algolia.
The npm package @algolia/autocomplete-preset-algolia receives a total of 562,635 weekly downloads. As such, @algolia/autocomplete-preset-algolia popularity was classified as popular.
We found that @algolia/autocomplete-preset-algolia demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 82 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.