T
TanStack12mo ago
like-gold

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
genetic-orange
genetic-orange12mo 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
like-gold
like-goldOP12mo ago
But useState only works in client components.
wise-white
wise-white12mo ago
If you only want to fetch on the server, you don't need react query. Just use server components 🤷‍♂️
like-gold
like-goldOP12mo ago
Ok thank you.

Did you find this page helpful?