Dev Helpers
← Back

Validated view label

Place this file at components/ValidatedViewLabel.tsx in an App Router project.

Open this example in the interactive library

Source code

"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>
  );
}