next Js 14 - server side rendering with app
Answered
Californian posted this in #help-forum
CalifornianOP
Hi !
How can I use getServerSideProps in my Next Js 14 app to do server side rendering while I have the app folder in my project ?
How can I use getServerSideProps in my Next Js 14 app to do server side rendering while I have the app folder in my project ?
Answered by Ray
by default, every component is server component. You could fetch the data inside the component in app router
13 Replies
@Californian Hi !
How can I use getServerSideProps in my Next Js 14 app to do server side rendering while I have the app folder in my project ?
by default, every component is server component. You could fetch the data inside the component in app router
Answer
CalifornianOP
Thank you ! Appreciate your reactivity !
CalifornianOP
Just out by curiosity, in which case you I use getServerSideProps then ? ( I am using next js 14)
@Californian Just out by curiosity, in which case you I use getServerSideProps then ? ( I am using next js 14)
when you are using page router
getServerSideProps doesn't work with app routerCalifornianOP
Thank you !
CalifornianOP
Sorry to bother you again ... But here is what I have done ! This is page (in app/test/page.tsx).
getTest.tsx is a call to my database Supabase. (typically, it queries all the data in the table test).
But it does not work. Is it the correct way to do it ? Because it does not work, and when I query it in the client side, it works properly !
getTest.tsx is a call to my database Supabase. (typically, it queries all the data in the table test).
But it does not work. Is it the correct way to do it ? Because it does not work, and when I query it in the client side, it works properly !
@Californian Sorry to bother you again ... But here is what I have done ! This is page (in app/test/page.tsx).
getTest.tsx is a call to my database Supabase. (typically, it queries all the data in the table test).
But it does not work. Is it the correct way to do it ? Because it does not work, and when I query it in the client side, it works properly !
if you are using supabase-js, you should fetch the data with
useState and useEffect hookhttps://supabase.com/docs/guides/getting-started/tutorials/with-nextjs
you may want to check out this guide
you may want to check out this guide
CalifornianOP
Hmm ok i see. All in this guide is what I did ! Does it mean that I can not use the server side of Next Js ? It seems I can just query my data in a client side ! Why I am asking that is because I wanted to benefit the performance of the server side rendering in Next Js. Do you get my point ? Thank you again for your answer
@Californian Hmm ok i see. All in this guide is what I did ! Does it mean that I can not use the server side of Next Js ? It seems I can just query my data in a client side ! Why I am asking that is because I wanted to benefit the performance of the server side rendering in Next Js. Do you get my point ? Thank you again for your answer
https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs#supabase-server-side-auth
you should use
you should use
@supabase/ssr package for ssrand the tutorial will guide you to create a browser client and a server client
CalifornianOP
I will look at it ! Thank you for your reactivity !