Default values support at the Provider level #1381
|
Hi, I'm one of the maintainers of Parca and we use a custom homegrown URLState library for the similar needs in Parca UI. Only recently we came across nuqs. It is looking very promising and we are now evaluating to migrate Parca UI to use We are happy to take up the effort to add this to nuqs but first we wanted to here your thoughts about this. |
Replies: 2 comments
|
The general recommendation would be to define a search params descriptor object that contains both the keys & associated parsers with their default values, which would look like what you have. For example: export const profileExplorerSearchParams = {
dashboard_items: parseAsNativeArrayOf(parseAsString).withDefault(['flamegraph'])
}
// Usage:
const [{ dashboard_items }, setSearchParams] = useQueryStates(profileExplorerSearchParams)
// You can also derive other things from this object, like a loader for one-time parsing:
const loadProfileExplorerSearchParams = createLoader(profileExplorerSearchParams)
// Or a link generator:
const getProfileExplorerHref = createSerializer(profileExplorerSearchParams)
|
|
Ok makes sense, will work with that. Thank you! |
The general recommendation would be to define a search params descriptor object that contains both the keys & associated parsers with their default values, which would look like what you have. For example: