Skip to main content

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

ParameterTypeDescription
searchTermstringThe search term to query. The hook debounces this value by 300ms.

Return Value

PropertyTypeDescription
resultsObjectThe predictive search response containing queries, collections, and products arrays.
results.queriesArray<{ text, trackingParameters }>Suggested search query strings.
results.collectionsArray<{ handle, trackingParameters }>Matching collections.
results.productsArray<{ handle, trackingParameters }>Matching products.
isLoadingbooleanWhether the search request is in progress. Only true when there is a valid (non-empty) search term.