useProductFilters
This hook fetches available product filters from Shopify for a given collection or search query. It supports live filter updates based on selected filter state.
Import
import { useProductFilters } from '@appmaker-xyz/shopify';
Basic Usage
// By collection ID
const { filters, isLoading, setSelectedFilters, getSingleFilter } = useProductFilters({
query: { collectionId: 'gid://shopify/Collection/123' },
});
// By collection handle
const { filters } = useProductFilters({
query: { collectionHandle: 'summer-collection' },
});
// By search query
const { filters } = useProductFilters({
query: { searchQuery: 'shoes' },
});
Parameters
| Parameter | Type | Description |
|---|---|---|
query | Object | Query input. Must contain one of: collectionId, collectionHandle, or searchQuery. |
preSelectedFilters | Object \| null | Optional pre-selected filters to initialize with. |
Return Value
| Property | Type | Description |
|---|---|---|
filters | Array | Array of available Shopify product filters. |
setSelectedFilters | Function | Updates the selected filters, triggering a refetch of available filters. |
getSingleFilter | Function | Returns a single filter by key. Signature: getSingleFilter({ filterKey }). |
isLoading | boolean | Whether the filter data is being fetched. |
isError | boolean | Whether the fetch failed. |
isSuccess | boolean | Whether the fetch succeeded. |