useRecentSearch
This hook manages the user's recent search history, stored in AsyncStorage. It automatically saves searches triggered by the product.search event and provides methods to retrieve, clear, and remove individual queries.
Import
import { useRecentSearch } from '@appmaker-xyz/shopify';
Basic Usage
const { queries, getQueries, clearQueries, removeQuery } = useRecentSearch();
// Display recent searches
queries.map((query) => <Text>{query}</Text>);
// Clear all search history
clearQueries();
// Remove a specific query
removeQuery('red shoes');
Return Value
| Property | Type | Description |
|---|---|---|
queries | string[] | Array of recent search query strings (most recent first, max 10). |
getQueries | Function | Fetches all recent search queries from storage. Returns Promise<string[]>. |
clearQueries | Function | Clears all recent search history. Returns Promise<void>. |
removeQuery | Function | Removes a specific query from history. Signature: removeQuery(query: string) => Promise<void>. |