Skip to content

Commit 380b111

Browse files
committed
fix: Handle falsy values
See #196.
1 parent 6f85fcc commit 380b111

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: src/useQueryState.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ export function useQueryState<T = string>(
7070
// unnecessary renders when other query parameters change.
7171
// URLSearchParams is already polyfilled by Next.js
7272
const query = new URLSearchParams(window.location.search)
73-
if (newValue) {
74-
query.set(key, serialize(newValue))
75-
} else {
73+
if (newValue === null || newValue === undefined) {
7674
// Don't leave value-less keys hanging
7775
query.delete(key)
76+
} else {
77+
query.set(key, serialize(newValue))
7878
}
7979

8080
// Remove fragment and query from asPath

0 commit comments

Comments
 (0)