Getting Started
The core Decurl workflow is: define a set of Search Fields first, then reuse the same rules in hooks or URLSearchParams codecs.
Install
@guanriyue/decurl supports React 18 and React 19, and requires React Router 7.
Define Fields
This uses several APIs:
fieldfreezes the type of a single FieldCodec.defineFieldsdefines a set of Search Fields and uses the object key for fields without an explicitname.- Decode primitives such as
pipe,shape, andelementOfcompose common parsing logic.
Decode URLSearchParams
If the canonical key is missing, Decurl tries legacy aliases. The URL above uses p=2, but the decoded business field is page.
Encode URLSearchParams
encode uses patch semantics by default:
- Only fields present in the patch are handled.
- Untouched fields from the base search are preserved.
- Alias fields are written with the canonical key.
- Writing a default value deletes the corresponding key by default.
See createURLSearchParamsCodec for more options.
Use It with React Router
React Router hooks can use the same Search Fields directly. Default hooks do not require an extra Provider.
Use useSearchValue when reading a single field. If you need to configure or isolate the search store, or reduce direct dependency on React Router useLocation, continue with @guanriyue/decurl/provided.
Continue reading: