36 lines
884 B
TypeScript
36 lines
884 B
TypeScript
import { useState, useEffect } from "react";
|
|
|
|
export interface Product {
|
|
id: string;
|
|
name: string;
|
|
price: number;
|
|
category: string;
|
|
description?: string;
|
|
}
|
|
|
|
export const useProductCatalog = () => {
|
|
const [products, setProducts] = useState<Product[]>([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
const fetchProducts = async () => {
|
|
try {
|
|
setIsLoading(true);
|
|
// Simulate API call
|
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
// Mock data would be loaded here
|
|
setProducts([]);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : "Failed to load products");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
fetchProducts();
|
|
}, []);
|
|
|
|
return { products, isLoading, error };
|
|
};
|