Skip to content

Commit

Permalink
fix: Handle falsy values
Browse files Browse the repository at this point in the history
See #196.
  • Loading branch information
franky47 committed Feb 26, 2021
1 parent 6f85fcc commit 380b111
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/useQueryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export function useQueryState<T = string>(
// unnecessary renders when other query parameters change.
// URLSearchParams is already polyfilled by Next.js
const query = new URLSearchParams(window.location.search)
if (newValue) {
query.set(key, serialize(newValue))
} else {
if (newValue === null || newValue === undefined) {
// Don't leave value-less keys hanging
query.delete(key)
} else {
query.set(key, serialize(newValue))
}

// Remove fragment and query from asPath
Expand Down

0 comments on commit 380b111

Please sign in to comment.