Skip to content

Why does QueryStatus return null for parser keys without default values? #827

Answered by franky47
Best-Sardar asked this question in Q&A
Discussion options

You must be logged in to vote

This is outlined in the docs: https://nuqs.47ng.com/docs/basic-usage#default-values

The main reason is, as you said, that null means no value. It's returned to indicate the absence of the search params key in the URL, or if the parser can't give you a meaningful value back (eg: using parseAsInteger, but the URL is ?foo=not-a-number).

null is also used to clear the search param from the URL on updates, a case where undefined would have been awkward:

const [state, setState] = useQueryState('foo')

// null clears the URL
setState(null)

// Using undefined would allow this, which is ambiguous:
setState()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by franky47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants