generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: useQueryStates does not update values correctly when config chan…
…ges (#908)
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/docs/src/app/playground/_demos/repro-907/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// https://github.com/47ng/nuqs/issues/907 | ||
|
||
'use client' | ||
|
||
import { parseAsString, useQueryStates } from 'nuqs' | ||
import { useState } from 'react' | ||
|
||
export default function Home() { | ||
const [nuqsConfig, setNuqsConfig] = useState< | ||
Record<string, typeof parseAsString> | ||
>({ | ||
p1: parseAsString, | ||
p2: parseAsString | ||
}) | ||
|
||
const [values] = useQueryStates(nuqsConfig) | ||
|
||
return ( | ||
<> | ||
<div className="flex gap-2"> | ||
<button | ||
onClick={() => setNuqsConfig({ p1: parseAsString })} | ||
className="border p-2" | ||
> | ||
Update config (remove one of the keys) | ||
</button> | ||
|
||
<button | ||
onClick={() => | ||
setNuqsConfig({ | ||
p1: parseAsString, | ||
p2: parseAsString, | ||
p3: parseAsString | ||
}) | ||
} | ||
className="border p-2" | ||
> | ||
Update config (add a new key) | ||
</button> | ||
|
||
<button | ||
onClick={() => | ||
setNuqsConfig({ | ||
p1: parseAsString, | ||
p5: parseAsString | ||
}) | ||
} | ||
className="border p-2" | ||
> | ||
Update config (replace a key) | ||
</button> | ||
</div> | ||
<div>Config keys: {JSON.stringify(Object.keys(nuqsConfig))}</div> | ||
<div>Result: {JSON.stringify(values)}</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters