Skip to content

Commit f198605

Browse files
committed
doc: Update options & callouts
1 parent d188356 commit f198605

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

packages/docs/content/docs/options.mdx

+19-14
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ internal state and stay in sync with each other.
125125

126126
## Transitions
127127

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
129129
to get loading states while the server is re-rendering server components with
130130
the updated URL.
131131

132-
Pass in the `startTransition` function from `useTransition` to the options
132+
Pass in the `startTransition{:ts}` function from `useTransition{:ts}` to the options
133133
to enable this behaviour:
134134

135135
<Callout title="Upcoming changes" type="warn">
@@ -144,10 +144,12 @@ import { useQueryState, parseAsString } from 'nuqs'
144144

145145
function ClientComponent({ data }) {
146146
// 1. Provide your own useTransition hook:
147+
// [!code word:startTransition:1]
147148
const [isLoading, startTransition] = React.useTransition()
148149
const [query, setQuery] = useQueryState(
149150
'query',
150151
// 2. Pass the `startTransition` as an option:
152+
// [!code word:startTransition:1]
151153
parseAsString().withOptions({ startTransition, shallow: false })
152154
)
153155
// 3. `isLoading` will be true while the server is re-rendering
@@ -170,38 +172,41 @@ function ClientComponent({ data }) {
170172

171173
## Clear on default
172174

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.
176177

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
179184
to [user feedback](https://x.com/fortysevenfx/status/1841610237540696261).
180185
</Callout>
181186

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}`:
184189

185190
```ts /clearOnDefault: true/
186191
useQueryState('search', {
187192
defaultValue: '',
188-
clearOnDefault: true
193+
clearOnDefault: false
189194
})
190195
```
191196

192197
<Callout title="Tip">
193198
Clearing the key-value pair from the query string can always be done by setting the state to `null{:ts}`.
194199
</Callout>
195200

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)
198203
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):
200205

201206
```ts
202207
const dateParser = createParser({
203208
parse: (value: string) => new Date(value.slice(0, 10)),
204209
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]
206211
})
207212
```

0 commit comments

Comments
 (0)