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.
chore: Add debug controls to playground
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 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,34 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
|
||
export default function DebugControl() { | ||
const [checked, setChecked] = React.useState(() => { | ||
if (typeof localStorage === 'undefined') { | ||
return false | ||
} | ||
return ( | ||
localStorage.getItem('debug')?.includes('next-usequerystate') ?? false | ||
) | ||
}) | ||
const update = React.useCallback(() => { | ||
setChecked(c => { | ||
const checked = !c | ||
if (typeof localStorage !== 'undefined') { | ||
if (checked) { | ||
localStorage.setItem('debug', 'next-usequerystate') | ||
} else { | ||
localStorage.removeItem('debug') | ||
} | ||
} | ||
return checked | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<span> | ||
<input type="checkbox" checked={checked} onChange={update} /> | ||
<label>Console debugging</label> | ||
</span> | ||
) | ||
} |