What to use instead of "getServerSideProps" in NextJS?
As most of you might be aware of getServerSideProps is slow and hard to use. Is there a better alternative method to use instead? Like using react-query maybe? I am not sure about it. I'd appreciate any recommendation 🙏
6 Replies
use trpc if you can. if you can’t for whatever reason then i’d recommend creating api routes and using react query. or if you want to use newer tech try out app dir and server components
but is it server side or client side request?
trpc: without ssr enabled: clients gets rendered page, page hydrates on client and trpc wouls request backend for the data
trpc with ssr: trpc would fetch data on the ssr request (not sure on the specifics of this. never used it) and client receives it
react query works the same way as trpc without ssr
app dir & server components are all server side.
so in conclusion trpc with ssr acts similar to getServerSideProps but with better features?
afaik yes. You’ll have to try it since i’ve never personally used it.
alright thanks for the suggestion @dan I'll keep this question open a bit more to see what others can say