diff --git a/packages/docs/content/docs/parsers/built-in.mdx b/packages/docs/content/docs/parsers/built-in.mdx
index b2b98a28..5e43a5ee 100644
--- a/packages/docs/content/docs/parsers/built-in.mdx
+++ b/packages/docs/content/docs/parsers/built-in.mdx
@@ -108,12 +108,13 @@ useQueryState('hex', parseAsHex.withDefault(0x00))
### Index
-Same as integer, but adds a `+1` offset to the query value. Useful for pagination indexes.
+Same as integer, but adds a `+1` offset to the serialized querystring (and `-1` when parsing).
+Useful for pagination indexes.
```ts
import { parseAsIndex } from 'nuqs'
-useQueryState('page', parseAsIndex.withDefault(0))
+const [pageIndex] = useQueryState('page', parseAsIndex.withDefault(0))
```
}>
diff --git a/packages/docs/content/docs/parsers/demos.tsx b/packages/docs/content/docs/parsers/demos.tsx
index b62da962..de52f182 100644
--- a/packages/docs/content/docs/parsers/demos.tsx
+++ b/packages/docs/content/docs/parsers/demos.tsx
@@ -1,9 +1,18 @@
'use client'
+import { CodeBlock } from '@/src/components/code-block.client'
import { QuerySpy } from '@/src/components/query-spy'
import { ContainerQueryHelper } from '@/src/components/responsive-helpers'
import { Button } from '@/src/components/ui/button'
import { Checkbox } from '@/src/components/ui/checkbox'
+import {
+ Pagination,
+ PaginationButton,
+ PaginationContent,
+ PaginationItem,
+ PaginationNext,
+ PaginationPrevious
+} from '@/src/components/ui/pagination'
import { Slider } from '@/src/components/ui/slider'
import { cn } from '@/src/lib/utils'
import { ChevronDown, ChevronUp, Minus, Star } from 'lucide-react'
@@ -173,25 +182,46 @@ export function HexParserDemo() {
}
export function IndexParserDemo() {
- const [value, setValue] = useQueryState('page', parseAsIndex)
+ const numPages = 5
+ const [pageIndex, setPageIndex] = useQueryState(
+ 'page',
+ parseAsIndex.withDefault(0).withOptions({ clearOnDefault: false })
+ )
return (
- {
- if (e.target.value === '') {
- setValue(null)
- } else {
- setValue(e.target.valueAsNumber)
- }
- }}
- placeholder="What page are you on?"
+
+
+
+ setPageIndex(p => Math.max(0, p - 1))}
+ />
+
+ {Array.from({ length: numPages }, (_, i) => (
+
+ setPageIndex(i)}
+ >
+ {i + 1}
+
+
+ ))}
+
+ setPageIndex(p => Math.min(numPages - 1, p + 1))}
+ />
+
+
+
+