help understanding ssr fetch functions
Answered
Barbary Lion posted this in #help-forum
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:
2 Replies
app router doesn't have
getServerSideProps, you should move the work inside getServerSideProps to the component instead