Next.js Discord

Discord Forum

Server or Client component?

Answered
Japanese flying squid posted this in #help-forum
Open in Discord
Japanese flying squidOP
So I was thinking that server components could be much faster than client component in the cases where I need to fetch data. For example I've page where I've to show user payment history. I've made all those type pages server side so it directly get's information from MongoDB. Is it good practise? or it's better to use API Routes in every page where I need to get some data from server?

Example Component
Answered by American Crow
Assuming you read the docs. Yes Server components for getting Data is the correct pattern.
Do not create Route Handlers to get Data that would be an Anti-Pattern resulting in an extra round trip, hence slower and exposing an API Endpoint
View full answer

2 Replies

Japanese flying squidOP
up
American Crow
Assuming you read the docs. Yes Server components for getting Data is the correct pattern.
Do not create Route Handlers to get Data that would be an Anti-Pattern resulting in an extra round trip, hence slower and exposing an API Endpoint
Answer