Socket
Socket
Sign inDemoInstall

@algolia/autocomplete-preset-algolia

Package Overview
Dependencies
Maintainers
68
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-preset-algolia

Presets for building autocomplete experiences with Algolia.


Version published
Weekly downloads
559K
decreased by-14.87%
Maintainers
68
Weekly downloads
 
Created

What is @algolia/autocomplete-preset-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.

What are @algolia/autocomplete-preset-algolia's main functionalities?

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>`;
              },
            },
          },
        ];
      },
    }),
  ],
});

Other packages similar to @algolia/autocomplete-preset-algolia

FAQs

Package last updated on 20 Dec 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc