generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow clearing all search params managed by useQueryStates (#622)
* feat: Allow clearing all search params managed by useQueryStates By passing `null` instead of an object, every key managed by that`useQueryStates` hook will be cleared from the URL.
- Loading branch information
Showing
6 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// <reference types="cypress" /> | ||
|
||
it('useQueryStates clear all', () => { | ||
cy.visit('/app/useQueryStates-clear-all?a=foo&b=bar') | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('button').click() | ||
cy.location('search').should('eq', '') | ||
}) |
24 changes: 24 additions & 0 deletions
24
packages/e2e/src/app/app/useQueryStates-clear-all/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use client' | ||
|
||
import { parseAsString, useQueryStates } from 'nuqs' | ||
import { Suspense } from 'react' | ||
|
||
export default function Page() { | ||
return ( | ||
<Suspense> | ||
<Client /> | ||
</Suspense> | ||
) | ||
} | ||
|
||
function Client() { | ||
const [, setValues] = useQueryStates({ | ||
a: parseAsString.withDefault(''), | ||
b: parseAsString.withDefault('') | ||
}) | ||
return ( | ||
<> | ||
<button onClick={() => setValues(null)}>Clear</button> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters