A query parameter describes a requested view but does not establish that the view exists. Match it against supported values before rendering its label.
Worked example
"use client";
// components/ValidatedViewLabel.tsx
import { Suspense } from "react";
import { useSearchParams } from "next/navigation";
function ValidatedViewLabelContent() {
const params = useSearchParams();
return <span>View: {params.get("view") === "grid" ? "Grid" : "List"}</span>;
}
export default function ValidatedViewLabel() {
return (
<Suspense fallback={<span>Loading view…</span>}>
<ValidatedViewLabelContent />
</Suspense>
);
}Implementation notes
Returning a safe default should leave readers aware of the active view. Keep the visible view selector and the rendered content in agreement.
Try it yourself
Visit the route with a valid option, a typo and no option.
Open the Next.js example →Editorial date July 5, 2026 · Published December 6, 2026