-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clearOnDefault doesn't work in useQueryStates #618
Comments
I see it doesnt work in that way however it let us to specify it (still an issue and I'm keeping this issue open to help maintainers). const [coordinates, setCoordinates] = useQueryStates(
{
lat: parseAsFloat.withDefault(45.18),
lng: parseAsFloat.withDefault(5.72),
temp: parseAsString
.withDefault("")
},
// the correct way to add option in useQueryStates
{
clearOnDefault: true,
},
) |
Thanks for the report! Yes, the global options should probably be merged with each parser's individual options, but this raises the question of which one should take precedence? As for clearOnDefault, I'd say |
Yes, updating the documentation will help a lot. Thank you. I agree that In this case, I had to create two separate |
So it seems the global options should be evaluated first, then any local per-parser options would take precedence, then any call-level options would take precedence over those, would that seem ok? You could then do: // Disclaimer: this code doesn't (yet) behave like this,
// it's an example of what option merging could look like.
const [{ lat, lng, temp, foo }, setSearchParams] = useQueryStates({
lat: parseAsFloat.withDefault(45.18),
lng: parseAsFloat.withDefault(5.72),
temp: parseAsString
.withDefault("")
.withOptions({ clearOnDefault: true }),
foo: parseAsBoolean
.withDefault(false)
.withOptions({ history: 'push' })
})
}, {
// Global options
scroll: false
})
// Only set lat & lng, history = replace, scroll = false
setSearchParams({ lat: 0, lng: 0 })
// Clear temp (set as default, equivalent to setSearchParams({ temp: null }))
// history = replace, scroll = false
setSearchParams({ temp: '' })
// Push foo with call-level options, history = push, scroll = false, shallow = false
setSearchParams({ foo: true }, { shallow: false }) |
Yes, exactly. That would be great. |
Order of precedence (first non-nullish wins): - call level - parser level - hook-global level (otherwise default). Also fixes a bug with `clearOnDefault` in useQueryState where a `true` top-level value could not be overriden by a call-level `false` value. Closes #618.
* fix: Allow parser-level options in useQueryStates Order of precedence (first non-nullish wins): - call level - parser level - hook-global level (otherwise default). Also fixes a bug with `clearOnDefault` in useQueryState where a `true` top-level value could not be overriden by a call-level `false` value. Closes #618.
🎉 This issue has been resolved in version 1.19.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 1.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Context
What's your version of
nuqs
?^1.17.7
Next.js information (obtained by running
next info
):Are you using:
basePath
option in your Next.js configwindowHistorySupport
flag in your Next.js configDescription
Hi, thanks fr this great package.
there is issue with clearing on default value when using
useQueryStates
and doesnt work correctly.Reproduction
for reproduction try to use this hook with few key like below:
So, in this example, when you try to set one of the coordinates but keep the
temp
untouched, you can still see&temp=
in the URL.The expected behavior is to only include those with values other than the default ones in the URL.
The text was updated successfully, but these errors were encountered: