Theo's Typesafe CultTTC
Theo's Typesafe Cult11mo ago
4 replies
Manqo

Handling Async Params and Suspense Queries in a T3 Stack Next.js App

I'm having issues with fetching data for my story/[storyId]/page.tsx component.

'use client'
import { notFound } from "next/navigation";
import { api } from "@/trpc/react";
import StoryDisplay from "@/app/_components/StoryDisplay";
import { use } from "react";

export default function Page({ params }: { params: Promise<{ id: string }> }) {
  const { id } = use(params); 
  
  const [story] = api.story.getById.useSuspenseQuery({id});
  
  if (!story) {
    notFound();
  }
  
  return <StoryDisplay story={story} />;
}

What kind of options do I have here? It seems that id requires await, while useSuspenseQuery requires a server component.

How should I tackle this issue using the T3 stack?
Was this page helpful?