Type-safe search params state manager for Next.js - Like React.useState, but stored in the URL query string
Overall
score
96%
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.
@generates
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.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-nuqsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10