Skip to content

Clearing all query parameters #684

Answered by franky47
sunwrobert asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah there is no easy way to do this with nuqs at the moment.

You could adapt your hook to do it in a shallow manner this way (untested):

export const useClearFilters = () => {
  const pathname = usePathname()
  return useCallback(() => {
    history.replaceState(null, '', pathname)
  }, [pathname])
}

One really manual way to do it would be to import all of my nuqs hooks and reset the values one by one but that seems naive.

This might make sense if there are unrelated search params you want to keep (eg: utm tracking or whatnot). You would have to collect all of your parsers in one place, and can reset them all at once this way:

const searchParamsFoo = {
  foo: parseAsString
}
const sear…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sunwrobert
Comment options

Answer selected by sunwrobert
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