usePokeFilters hook provides a comprehensive filtering and sorting system for Pokemon lists, integrating with the global tweaks store and supporting debounced search, region filtering, type filtering, and multiple sort options.
Signature
Parameters
Array of Pokemon summary objects to filter and sort. Each object should contain:
id(number): Pokemon IDname(string): Pokemon nametypes(string[]): Array of type namesimage(string): Sprite URL
Optional configuration object:
debounce(number): Milliseconds to debounce search input (default: 0)
Returns
Object containing filtered list, state, and control functions:
Usage Example
Filter Behavior
Filters are applied in the following order:1. Search Filter
Matches Pokemon by name or ID (case-insensitive):"pika"→ Matches Pikachu, Pikachu-Libre, etc."25"→ Matches Pikachu (ID 25), also 250+ IDs"char"→ Matches Charizard, Charmeleon, Charmander
2. Region Filter
Filters Pokemon by their Pokedex ID range:- Kanto: 1-151
- Johto: 152-251
- Hoenn: 252-386
- Sinnoh: 387-493
- Unova: 494-649
- Kalos: 650-721
- Alola: 722-809
- Galar: 810-905
- Paldea: 906+
3. Type Filter
Filters Pokemon that have at least one of the selected types:- Multiple types use OR logic (Pokemon must have at least one selected type)
- Selecting
["fire", "water"]shows all Fire-type OR Water-type Pokemon - Pikachu (Electric) won’t show if only Fire and Water are selected
4. Sort Order
Sorts the filtered results:"id-asc": ID ascending (1, 2, 3…)"id-desc": ID descending (905, 904, 903…)"name-asc": Alphabetical A-Z"name-desc": Alphabetical Z-A
Type Toggle Function
ThetoggleType function adds or removes types from the filter:
Performance Optimization
The hook usesuseMemo to prevent unnecessary recalculations:
- Source
pokeListchanges - Debounced search value changes
- Type filters change
- Sort order changes
- Region selection changes
State Persistence
Filter state is managed byuseTweaksStore, which persists to sessionStorage:
- Search query is not persisted (resets on refresh)
- Region, types, and sort are persisted across page navigations
- Page number resets to 1 when filters change
Complete Example
Related
- useDebounce Hook - Used internally for search debouncing
- usePaginate Hook - Pair with this for paginated filtered results
- Tweaks Store - Manages filter state
- Pokemon Summary Adapter - Creates the data structure used by this hook