Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@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.
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 85 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.