@@ -125,11 +125,11 @@ internal state and stay in sync with each other.
125
125
126
126
## Transitions
127
127
128
- When combined with ` shallow: false{:ts} ` , you can use React's ` useTransition ` hook
128
+ When combined with ` shallow: false{:ts} ` , you can use React's ` useTransition{:ts} ` hook
129
129
to get loading states while the server is re-rendering server components with
130
130
the updated URL.
131
131
132
- Pass in the ` startTransition ` function from ` useTransition ` to the options
132
+ Pass in the ` startTransition{:ts} ` function from ` useTransition{:ts} ` to the options
133
133
to enable this behaviour:
134
134
135
135
<Callout title = " Upcoming changes" type = " warn" >
@@ -144,10 +144,12 @@ import { useQueryState, parseAsString } from 'nuqs'
144
144
145
145
function ClientComponent({ data }) {
146
146
// 1. Provide your own useTransition hook:
147
+ // [!code word:startTransition:1]
147
148
const [isLoading, startTransition] = React .useTransition ()
148
149
const [query, setQuery] = useQueryState (
149
150
' query' ,
150
151
// 2. Pass the `startTransition` as an option:
152
+ // [!code word:startTransition:1]
151
153
parseAsString ().withOptions ({ startTransition , shallow: false })
152
154
)
153
155
// 3. `isLoading` will be true while the server is re-rendering
@@ -170,38 +172,41 @@ function ClientComponent({ data }) {
170
172
171
173
## Clear on default
172
174
173
- By default, when the state is set to the default value, the search parameter is
174
- ** not** removed from the URL, and is reflected explicitly. This is because
175
- ** default values _ can_ change** , and the meaning of the URL along with it.
175
+ When the state is set to the default value, the search parameter is
176
+ removed from the URL, instead of being reflected explicitly.
176
177
177
- <Callout title = " Upcoming changes" type = " warn" >
178
- In ` nuqs@2.0.0 ` , clearOnDefault will be set to ` true{:ts} ` by default, in response
178
+ However, sometimes you might want to keep the search parameter in the URL,
179
+ because ** default values _ can_ change** , and the meaning of the URL along with it.
180
+
181
+ <Callout title = " Example of defaults changing" >
182
+ In ` nuqs@1.x.x ` , ` clearOnDefault{:ts} ` was ` false{:ts} ` by default.<br />
183
+ in ` nuqs@2.0.0 ` , ` clearOnDefault{:ts} ` is now ` true{:ts} ` by default, in response
179
184
to [ user feedback] ( https://x.com/fortysevenfx/status/1841610237540696261 ) .
180
185
</Callout >
181
186
182
- If you want to remove the search parameter from the URL when it's set to the default
183
- value, you can set ` clearOnDefault ` to ` true {:ts}` :
187
+ If you want to keep the search parameter in the URL when it's set to the default
188
+ value, you can set ` clearOnDefault ` to ` false {:ts}` :
184
189
185
190
``` ts /clearOnDefault: true/
186
191
useQueryState (' search' , {
187
192
defaultValue: ' ' ,
188
- clearOnDefault: true
193
+ clearOnDefault: false
189
194
})
190
195
```
191
196
192
197
<Callout title = " Tip" >
193
198
Clearing the key-value pair from the query string can always be done by setting the state to ` null{:ts} ` .
194
199
</Callout >
195
200
196
- This option compares the set state against the default value using ` === ` reference
197
- equality, so if you are using a [ custom parser] ( ./parsers/making-your-own )
201
+ This option compares the set state against the default value using ` ==={:ts} `
202
+ reference equality, so if you are using a [ custom parser] ( ./parsers/making-your-own )
198
203
for a state type that wouldn't work with reference equality, you should provide
199
- the ` eq ` function to your parser (this is done for you in built-in parsers):
204
+ the ` eq{:ts} ` function to your parser (this is done for you in built-in parsers):
200
205
201
206
``` ts
202
207
const dateParser = createParser ({
203
208
parse : (value : string ) => new Date (value .slice (0 , 10 )),
204
209
serialize : (date : Date ) => date .toISOString ().slice (0 , 10 ),
205
- eq : (a : Date , b : Date ) => a .getTime () === b .getTime ()
210
+ eq : (a : Date , b : Date ) => a .getTime () === b .getTime () // [!code highlight]
206
211
})
207
212
```
0 commit comments