That is my code. I use prisma for fetching data from my postgreSQL db. The problem is that getServerSideProps is never invoked. The log message is not even printed in a console. The file is located in app folder
*page.tsx*
import Header from "./HomePageComponents/Header/Header";
import RestaurantCards from "./HomePageComponents/RestaurantCards/RestaurantCards";
import { PrismaClient } from "@prisma/client";
import { NextPage } from "next";
export const getServerSideProps = async () => {
const prisma = new PrismaClient();
const restaurants = await prisma.restaurant.findMany();
console.log("Logging: ", restaurants);
return { props: { restaurants } };
};
const Home: NextPage<any> = (props) => {
return (
<>
<Header />
<RestaurantCards />
</>
);
};
export default Home;
Edit 1:
The possible answer is that in the app router we can't use getServerSideProps and other traditional for nextjs fetching methods. Instead, we have to turn our components into async components and fetch data inside of the components. Fetching will occur during server-side rendering. A problem may occur with as called Async Server Component TypeScript Error during assigning types to your functional component.