generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathpage.tsx
36 lines (32 loc) · 959 Bytes
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use client'
import { parseAsInteger, subscribeToQueryUpdates, useQueryState } from 'nuqs'
import React from 'react'
export default function BuilderPatternDemoPage() {
const [counter, setCounter] = useQueryState(
'counter',
parseAsInteger.withDefault(0)
)
React.useEffect(() => {
const off = subscribeToQueryUpdates(({ search }) =>
console.log(search.toString())
)
return off
}, [])
return (
<>
<h1>Subscribing to query updates</h1>
<button onClick={() => setCounter(x => x - 1)}>-</button>
<button onClick={() => setCounter(x => x + 1)}>+</button>
<button onClick={() => setCounter(null)}>Reset</button>
<p>{counter}</p>
<p>
<em>Check the console</em>
</p>
<p>
<a href="https://github.com/47ng/nuqs/tree/next/packages/docs/src/app/(pages)/playground/subscribeToQueryUpdates/page.tsx">
Source on GitHub
</a>
</p>
</>
)
}