usePredictiveSearch
This hook provides real-time predictive search results from Shopify's predictive search API. It debounces the search term (300ms) and returns matching queries, collections, and products.
Import
import { usePredictiveSearch } from '@appmaker-xyz/shopify';
Basic Usage
const { results, isLoading } = usePredictiveSearch(searchTerm);
// Access result sections
const suggestedQueries = results?.queries;
const matchingCollections = results?.collections;
const matchingProducts = results?.products;
Parameters
| Parameter | Type | Description |
|---|---|---|
searchTerm | string | The search term to query. The hook debounces this value by 300ms. |
Return Value
| Property | Type | Description |
|---|---|---|
results | Object | The predictive search response containing queries, collections, and products arrays. |
results.queries | Array<{ text, trackingParameters }> | Suggested search query strings. |
results.collections | Array<{ handle, trackingParameters }> | Matching collections. |
results.products | Array<{ handle, trackingParameters }> | Matching products. |
isLoading | boolean | Whether the search request is in progress. Only true when there is a valid (non-empty) search term. |