Skip to main content

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​

PropertyTypeDescription
queriesstring[]Array of recent search query strings (most recent first, max 10).
getQueriesFunctionFetches all recent search queries from storage. Returns Promise<string[]>.
clearQueriesFunctionClears all recent search history. Returns Promise<void>.
removeQueryFunctionRemoves a specific query from history. Signature: removeQuery(query: string) => Promise<void>.