Default as null
#490
-
For a better DX, I want to use a default value instead of import { useQueryState } from 'nuqs';
export const useNullableQueryState = <T>(
nullValue: T,
...args: Parameters<typeof useQueryState<T>>
) => {
const [state, setState] = useQueryState(...args);
return [
(state ?? nullValue) as T,
(value: T) => {
void setState(value === nullValue ? null : (value as any));
},
] as const;
}; Is there a |
Beta Was this translation helpful? Give feedback.
Answered by
franky47
Feb 10, 2024
Replies: 1 comment 1 reply
-
Would #488 fit your purpose? It's been discussed a few times now, I'll probably add an option to clear the query when setting to the default (with a disclaimer in the docs about changing defaults). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@zbeyens I've opened #493 to implement this option, let me know what you think there.