I am working on a Next.js project (Prisma as ORM) that contains multiple parts where dynamic pages are created often.
Until now, I fetched the data using getStaticProps and getStaticPaths. I realized only now that these are only run at build time and my project only works in development for the moment.
I tried to change the data fetching to useSWR with a fetcher:
...
const fetcher = (...args) => fetch(...args).then((res) => res.json());
export default function View() {
const { data, isLoading, error } = useSWR('/api/survey-data', fetcher);
const survey = data?.survey;
if(error) return <div>Failed to load</div>;
if(isLoading) return <Loading/>;
...
Passing through an api that calls a function that gets the data from the database using Prisma, which causes this error:
Unhandled Runtime Error Error: PrismaClient is unable to be run in the browser
I am unable to find a concrete example on what is the best practice for my use case. How can I fetch my data when Prisma can't run on the client?
Thank you for any insight!