@@ -124,7 +124,7 @@ The loader function will accept the following input types to parse search params
124
124
## Cache
125
125
126
126
<Callout >
127
- This feature is available for Next.js only.
127
+ The ` next/server/cache ` feature is available for Next.js app router only.
128
128
</Callout >
129
129
130
130
If you wish to access the searchParams in a deeply nested Server Component
@@ -135,12 +135,9 @@ Think of it as a loader combined with a way to propagate the parsed values down
135
135
the RSC tree, like Context would on the client.
136
136
137
137
``` ts title="searchParams.ts"
138
- import {
139
- createSearchParamsCache ,
140
- parseAsInteger ,
141
- parseAsString
142
- } from ' nuqs/server'
143
- // Note: import from 'nuqs/server' to avoid the "use client" directive
138
+ import { createSearchParamsCache } from ' nuqs/server/cache'
139
+ import { parseAsInteger , parseAsString } from ' nuqs/server'
140
+ // Note: import parsers from 'nuqs/server' to avoid the "use client" directive
144
141
145
142
export const searchParamsCache = createSearchParamsCache ({
146
143
// List your search param keys and associated parsers here:
@@ -176,17 +173,24 @@ function Results() {
176
173
}
177
174
```
178
175
176
+ <Callout type = " warn" title = " Deprecation notice" >
177
+ The cache feature is also accessible from ` nuqs/server ` in nuqs@^2, but
178
+ will be removed from that import in nuqs@3.0.0.
179
+ Please update your imports to ` nuqs/server/cache ` for a smoother transition.
180
+
181
+ This is to allow non-Next.js server code to use the ` nuqs/server ` import
182
+ without having to install React canary for the ` cache ` function.
183
+ </Callout >
184
+
179
185
The cache will only be valid for the current page render
180
186
(see React's [ ` cache ` ] ( https://react.dev/reference/react/cache ) function).
181
187
182
188
Note: the cache only works for ** server components** , but you may share your
183
189
parser declaration with ` useQueryStates ` for type-safety in client components:
184
190
185
191
``` ts title="searchParams.ts"
186
- import {
187
- parseAsFloat ,
188
- createSearchParamsCache
189
- } from ' nuqs/server'
192
+ import { parseAsFloat } from ' nuqs/server'
193
+ import { createSearchParamsCache } from ' nuqs/server/cache'
190
194
191
195
export const coordinatesParsers = {
192
196
lat: parseAsFloat .withDefault (45.18 ),
0 commit comments