Open this example in the interactive library
Source code
"use client";
// components/ToggleArchivedResults.tsx
import { Suspense } from "react";
import Link from "next/link";
import { useSearchParams, usePathname } from "next/navigation";
function ToggleArchivedResultsContent() {
const p = useSearchParams();
const path = usePathname();
const next = new URLSearchParams(p);
const show = p.get("archived") === "1";
if (show) next.delete("archived");
else next.set("archived", "1");
return (
<Link href={path + (next.size ? "?" + next : "")} scroll={false}>
{show ? "Hide" : "Show"} archived
</Link>
);
}
export default function ToggleArchivedResults() {
return (
<Suspense fallback={<span>Loading view…</span>}>
<ToggleArchivedResultsContent />
</Suspense>
);
}
