Changes
Co-authored-by: wolfoftyreso-debug <250630591+wolfoftyreso-debug@users.noreply.github.com>
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
Reference in New Issue
Block a user