diff --git a/packages/playground/src/app/layout.tsx b/packages/playground/src/app/layout.tsx index ae0c1bf5..32d264b3 100644 --- a/packages/playground/src/app/layout.tsx +++ b/packages/playground/src/app/layout.tsx @@ -1,3 +1,4 @@ +import dynamic from 'next/dynamic' import React, { Suspense } from 'react' import { HydrationMarker } from '../components/hydration-marker' @@ -7,6 +8,18 @@ export const metadata = { 'useQueryState hook for Next.js - Like React.useState, but stored in the URL query string' } +const DebugControlsSkeleton = () => ( + + + + +) + +const DebugControl = dynamic(() => import('../components/debug-control'), { + ssr: false, + loading: DebugControlsSkeleton +}) + export default function RootLayout({ children }: { @@ -27,6 +40,10 @@ export default function RootLayout({ How it works + {' • '} + }> + +
{children} diff --git a/packages/playground/src/components/debug-control.tsx b/packages/playground/src/components/debug-control.tsx new file mode 100644 index 00000000..d5641866 --- /dev/null +++ b/packages/playground/src/components/debug-control.tsx @@ -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 ( + + + + + ) +}