generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's done by URLSearchParams.toString() already. Add a demo to test it out. Fixes a double-encoding cosmetic issue found by @tacomanator in #343 (comment)
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use client' | ||
|
||
import { parseAsJson, useQueryState } from '../../../../dist' | ||
import { parseAsArrayOf } from '../../../lib' | ||
|
||
const escaped = '-_.!~*\'()?#/&,"`<>{}[]@$£%+=:;' | ||
|
||
export default function CompoundParsersDemo() { | ||
const [code, setCode] = useQueryState( | ||
'code', | ||
parseAsJson<any>().withDefault({}) | ||
) | ||
const [array, setArray] = useQueryState( | ||
'array', | ||
parseAsArrayOf(parseAsJson<any>()).withDefault([]) | ||
) | ||
return ( | ||
<> | ||
<h1>Compound parsers</h1> | ||
<section> | ||
<h2>JSON</h2> | ||
<button onClick={() => setCode({})}>Set to {'{}'}</button> | ||
<button onClick={() => setCode([])}>Set to {'[]'}</button> | ||
<button onClick={() => setCode([1, 2, 3])}>Set to {'[1,2,3]'}</button> | ||
<button onClick={() => setCode({ hello: 'world' })}> | ||
Set to {'{hello:"world"}'} | ||
</button> | ||
<button onClick={() => setCode({ escaped })}> | ||
Set to escaped chars | ||
</button> | ||
<pre> | ||
<code>{JSON.stringify(code, null, 2)}</code> | ||
</pre> | ||
</section> | ||
<section> | ||
<h2>Arrays</h2> | ||
<button onClick={() => setArray(null)}>Clear</button> | ||
<button onClick={() => setArray(a => [...a, {}])}>Push {'{}'}</button> | ||
<button onClick={() => setArray(a => [...a, [1, 2, 3]])}> | ||
Push {'[1,2,3]'} | ||
</button> | ||
<button onClick={() => setArray(a => [...a, { hello: 'world' }])}> | ||
Push hello world | ||
</button> | ||
<button onClick={() => setArray(a => [...a, { escaped }])}> | ||
Push escaped chars | ||
</button> | ||
<pre> | ||
<code>{JSON.stringify(array, null, 2)}</code> | ||
</pre> | ||
</section> | ||
</> | ||
) | ||
} |
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