T
TanStack15mo ago
robust-apricot

Always fetch on the server?

How can I fetch my data on the server and not on the client on my Next.js app? Maybe I am just dump but I could not get it from the docs. Defining the Query Client forces the page to be an client component. But how can I then fetch on the server and have the advantage of e.g. env variables and don't have to reveal the API endpoint to the client. It is not logical to me to transform everything to an client component with the Query Client definition when I want to fetch on the server. Also I want to keep as many components as possible server side rendered. Hope you can help me with that.
4 Replies
sunny-green
sunny-green15mo ago
TanStack | High Quality Open-Source Software for Web Developers
Headless, type-safe, powerful utilities for complex workflows like Data Management, Data Visualization, Charts, Tables, and UI Components.
From An unknown user
From An unknown user
robust-apricot
robust-apricotOP15mo ago
But useState only works in client components.
flat-fuchsia
flat-fuchsia15mo ago
If you only want to fetch on the server, you don't need react query. Just use server components 🤷‍♂️
robust-apricot
robust-apricotOP15mo ago
Ok thank you.

Did you find this page helpful?