Skip to content

Commit

Permalink
doc: Add docs for urlKeys in serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Oct 30, 2024
1 parent 4f8e2f9 commit 21eed2b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/docs/content/docs/utilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,38 @@ serialize(url, { foo: 'bar' }) // https://example.com/path?baz=qux&foo=bar
serialize('?remove=me', { foo: 'bar', remove: null }) // ?foo=bar
```

### Shorter search params keys

Just like [`useQueryStates{:ts}`](./batching#shorter-search-params-keys), you can
specify a `urlKeys{:ts}` object to map the variable names defined by the parsers
to shorter keys in the URL:

```ts
const serialize = createSerializer(
{
// Use variable names that make sense for your domain/business logic
latitude: parseAsFloat,
longitude: parseAsFloat,
zoomLevel: parseAsInteger
},
{
// And remap them to shorter keys in the URL
urlKeys: {
latitude: 'lat',
longitude: 'lng',
zoomLevel: 'z'
}
}
)

serialize({
latitude: 45.18,
longitude: 5.72,
zoomLevel: 12
})
// ?lat=45.18&lng=5.72&z=12
```

## Parser type inference

To access the underlying type returned by a parser, you can use the
Expand Down

0 comments on commit 21eed2b

Please sign in to comment.