next.js/examples/api-routes-middleware/pages/index.tsx
index.tsx14 lines392 B
import useSWR from "swr";

const fetcher = (url: string) => fetch(url).then((res) => res.text());

export default function Index() {
  const { data, error, isLoading } = useSWR<string>("/api/cookies", fetcher);

  if (error) return <div>Failed to load</div>;
  if (isLoading) return <div>Loading...</div>;
  if (!data) return null;

  return <div>{`Cookie from response: "${data}"`}</div>;
}
Quest for Codev2.0.0
/
SIGN IN