Skip to main content
Autocomplete is also available as an experimental widget in InstantSearch, making it easier to integrate into your search experience. For more information, see the API reference for InstantSearch.js or React InstantSearch.
The createLocalStorageRecentSearchesPlugin plugin connects with the user’s local storage to fetch and save recent searches. To use your own storage, check createRecentSearchesPlugin. See demo

Installation

First, you need to install the plugin.
Then import it in your project:
JavaScript
If you don’t use a package manager, you can use the HTML script element:
HTML

Example

This example uses the plugin within autocomplete-js.
JavaScript
You can combine this plugin with the Query Suggestions plugin to populate the empty screen with recent and popular queries.
JavaScript

Parameters

string
required
A local storage key to identify where to save and retrieve the recent searches.For example:
  • "navbar"
  • "search"
  • "main"
The plugin namespaces all keys to avoid collisions.
number
The number of recent searches to display.
A search function to retrieve recent searches from. This function is called in storage.getAll to retrieve recent searches and is useful to filter and highlight recent searches when typing a query.
JavaScript
function
Type definition
This function takes the original source as a parameter and returns a modified version of that source.For example:Change Autocomplete stateUsually, when a link in the Autocomplete menu is selected, the menu closes. However, to keep the menu visible after a selection is made, use transformSource to set the isOpen state:
JavaScript
Create linksTurns Query Suggestions into clickable Google search links:
AutocompleteRecentSearchesPluginTranslations
Type definition
A dictionary of translations to support internationalization.

Returns

data

SearchParameters => SearchParameters
Optimized Algolia search parameters. This is useful when using the plugin along with the Query Suggestions plugin.This function enhances the provided search parameters by:
  • Excluding Query Suggestions that are already displayed in recent searches.
  • Using a shared hitsPerPage value to get a group limit of Query Suggestions and recent searches.
(item: TItem) => void
A function that adds an item to the recent searches local storage.
(id: string) => void
A function that removes an item from the recent searches local storage.
() => TItem[]
A function that returns the items from the recent searches local storage.
Last modified on May 19, 2026