createRecentSearchesPlugin plugin lets you implement your own storage.
To connect with the user’s local storage,
check createLocalStorageRecentSearchesPlugin.
Open CodeSandbox
Run and edit the createRecentSearchesPlugin example in CodeSandbox.
Installation
First, you need to install the plugin.JavaScript
script element:
HTML
Example
This example uses the plugin withinautocomplete-js.
You’re in charge of implementing the storage to fetch and save recent searches.
JavaScript
JavaScript
JavaScript
Parameters
RecentSearchesStorage
required
The storage to fetch from and save recent searches into.
TypeScript
function
Type definition
transformSource to set the isOpen state:JavaScript
AutocompleteRecentSearchesPluginTranslations
TypeScript
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 storage.
(id: string) => void
A function that removes an item from the recent searches storage.
() => TItem[]
A function that returns the items from the recent searches storage.