evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
A reusable filtering component for an e-commerce product catalog that stores filter state in URL query parameters.
Build a TypeScript React hook called useProductFilters that manages product filtering state using URL query parameters. The hook should handle four filter parameters:
q) - A text search string that can be empty or have a valuecategory) - Must be one of: "electronics", "clothing", "books", "home", or "toys". Should default to "electronics" when not specifiedminPrice) - An integer value in cents. Should default to 0 when not specifiedinStock) - A boolean flag. Should default to false when not specifiedThe hook must return an object with the current filter values and setter functions for each parameter.
type Category = "electronics" | "clothing" | "books" | "home" | "toys";
interface ProductFilters {
search: string | null;
category: Category;
minPrice: number;
inStock: boolean;
}
interface ProductFilterSetters {
setSearch: (value: string | null) => void;
setCategory: (value: Category) => void;
setMinPrice: (value: number) => void;
setInStock: (value: boolean) => void;
}
export function useProductFilters(): ProductFilters & ProductFilterSetters;Provides type-safe URL query state management for React.