Next.js Discord

Discord Forum

SSR table with pagination UI for an external API

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hey everyone!
I'm trying to use @tanstack/react-table in a NextJS 14 project and take advantage of SSR and Suspense with loading components.

Currently, my server component looks like this:
import { client } from "@/lib/stormgateworld";

import LeaderboardTable from "./table";

export default async function LeaderboardPage() {
  const { data } = await client.GET("/v0/leaderboards/ranked_1v1", {
    params: {
      query: {
        page: 1,
      },
    },
  });


  if (!data) {
    return null;
  }

  return (
    <div className="my-6">
      <LeaderboardTable data={data} />
    </div>
  );
}


where <LeaderboardTable /> takes in data to then call useReactTable. I want to add pagination where a user can click between pages but this would require some state management and I can't use useState in a server component where my query is being made.

SSR is frankly a new concept to me but if anyone could point me in a direction of an appropriate pattern for this, that'd be great.

I could manually call client.GET and set data and recall the query whenever my pagination state changes, but I was wondering if this is achievable while leaving the query on the server: changing page from 1 to 2 based on user click.

Thanks in advance!

4 Replies

West African LionOP
yes that’s essentially my problem - where can that come from? i can’t use const [pageIndex, setPageIndex] = useState(1) in a server component
West African LionOP
it seems like pagination all has to be done on the client and i could use getServerSideProps only to preload the initial data but subsequent queries need to be initiated from the client
Phainopepla
So there is no way of doing SSR pagination ? Like invalidating the cached route so the data is refetched using new searchParams or something like that ?