Overview
@woltz/react-rich-domain provides React hooks and UI components for seamless integration with rich-domain’s Criteria API. It’s distributed via the shadcn/ui registry, making installation simple and allowing you to own the code.
useCriteria Hook
Full-featured hook for managing filters, sorting, pagination, and search
Filter Component
Pre-built UI component for building dynamic filter interfaces
URL Sync
Automatic synchronization with URL query parameters
Persistence
Optional localStorage persistence for filter state
Installation
Install components using the shadcn CLI:The Filter component requires shadcn/ui components:
button, input,
popover, and calendar.What Gets Installed
useCriteria Hook
A comprehensive hook for managing Criteria state in React applications.Basic Usage
Options
Return Value
With React Query
URL Synchronization
EnablesyncWithUrl to automatically sync criteria state with URL query parameters:
localStorage Persistence
UsepersistKey to persist criteria state across page reloads:
Filter Component
A pre-built, customizable filter UI component that integrates withuseCriteria.
Basic Usage
QueryFilter Type
Field Types and Operators
The Filter component automatically shows the appropriate operators based on field type:| Type | Operators |
|---|---|
string | equals, notEquals, contains, startsWith, endsWith, in, notIn, isNull, isNotNull |
number | equals, notEquals, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, between, in, notIn, isNull, isNotNull |
date | equals, notEquals, greaterThan, lessThan, between, isNull, isNotNull |
boolean | equals, notEquals, isNull, isNotNull |
With Options (Select Fields)
For fields with predefined values, use theoptions property:
Nested Fields
Support for nested entity paths:Complete Example
A full example combininguseCriteria, Filter, and a data table:
API Reference
useCriteria Options
| Option | Type | Default | Description |
|---|---|---|---|
initialPage | number | 1 | Starting page number |
pageSize | number | 20 | Items per page |
initialFilters | Filter[] | [] | Pre-applied filters |
initialSort | Order[] | [] | Pre-applied sorting |
initialSearch | object | undefined | Pre-applied search |
onChange | function | undefined | Callback when criteria changes |
persistKey | string | undefined | localStorage key for persistence |
syncWithUrl | boolean | false | Sync state with URL params |
Filter Props
| Prop | Type | Required | Description |
|---|---|---|---|
fields | QueryFilter[] | Yes | Available fields for filtering |
filters | Filter[] | Yes | Current active filters |
addOrReplaceByIndex | function | Yes | Add or update a filter |
removeFilter | function | Yes | Remove a filter by index |
clearFilters | function | Yes | Clear all filters |