// app/products/page.tsx 'use client'; import { useState } from 'react'; export default function ProductsPage() { const [category, setCategory] = useState(''); const [sort, setSort] = useState('price'); const [limit, setLimit] = useState('10'); const [products, setProducts] = useState([]); const [loading, setLoading] = useState(false); const fetchProducts = async () => { setLoading(true); try { // Construct URL with query parameters const url = new URL('https://api.example.com/products'); if (category) url.searchParams.append('category', category); if (sort) url.searchParams.append('sort', sort); if (limit) url.searchParams.append('limit', limit); const response = await fetch(url.toString()); const data = await response.json(); setProducts(data.products); } catch (error) { console.error('Error fetching products:', error); } finally { setLoading(false); } }; return (

Product Search

setCategory(e.target.value)} className="border p-2 rounded" placeholder="electronics, clothing, etc." />
setLimit(e.target.value)} className="border p-2 rounded" min="1" max="100" />
{products.length > 0 && (

Results

{products.map((product) => (

{product.name}

Category: {product.category}

Price: ${product.price}

))}
)}
); }