Co-authored-by: wolfoftyreso-debug <250630591+wolfoftyreso-debug@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-07-11 12:49:40 +00:00
parent fef1b4ca0e
commit 582d5aea80
3 changed files with 0 additions and 454 deletions
-33
View File
@@ -1,33 +0,0 @@
import { useState, useEffect } from 'react';
import { storefrontApiRequest, STOREFRONT_PRODUCTS_QUERY, ShopifyProduct } from '@/lib/shopify';
export function useShopifyProducts(query?: string) {
const [products, setProducts] = useState<ShopifyProduct[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
async function fetchProducts() {
setIsLoading(true);
setError(null);
try {
const data = await storefrontApiRequest(STOREFRONT_PRODUCTS_QUERY, {
first: 10,
query: query || null
});
if (data?.data?.products?.edges) {
setProducts(data.data.products.edges);
}
} catch (err) {
console.error('Failed to fetch products:', err);
setError('Kunde inte ladda produkter');
} finally {
setIsLoading(false);
}
}
fetchProducts();
}, [query]);
return { products, isLoading, error };
}