Next.js Discord

Discord Forum

help understanding ssr fetch functions

Answered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
import type { InferGetServerSidePropsType, GetServerSideProps } from 'next';
import { type MCList } from '@/lib/servers';

export const getServerSideProps: GetServerSideProps<{
 MCList: MCList;
}> = async () => {
 const res = await fetch('http://localhost:3000/api/servers/');
 const MCList = await res.json();
 return { props: { MCList } };
};

export default async function Home(props: InferGetServerSidePropsType<typeof getServerSideProps>) {
 console.log(props);
 return (
  <main className="flex min-h-screen flex-col items-center justify-between p-24">
   <pre></pre>
  </main>
 );
}

as props i get:
{ params: {}, searchParams: {} }

and im supposed to get the response data from my nextjs api route:
Answered by Ray
page.js receive params and searchParms from props
View full answer

2 Replies