Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

Do not query db in server components

74,112 görüntüleme • 1 yıl önce •via X (Twitter)

11 Yorum

object Object profil fotoğrafı
object Object1 yıl önce

or use Server Actions, which are only executed on the server, but can be called from both client and server components. Only downfall is you can't call them from a route handler (IIRC)

Alex Sidorenko profil fotoğrafı
Alex Sidorenko1 yıl önce

The video applies to server function mutations as well. You can benefit from using data access layer in your server actions. P.S. Don't use server actions for data fetching as they execute sequentially.

MazrikBeats - check mes sons bg profil fotoğrafı
MazrikBeats - check mes sons bg1 yıl önce

Or use tRPC

freddie profil fotoğrafı
freddie1 yıl önce

so move backend code to a different file so it won’t leak, now that react allows you to call the backend in your components kind of preferred getServerSideProps then

Alex Sidorenko profil fotoğrafı
Alex Sidorenko1 yıl önce

React didn't come up with the concept of a data access layer. It's a general architecture pattern in software design. It's just the more React bridges the gap between client and server, the more we get exposed to backend practices that were hidden by the BE/FE split before.

Rafaell Lycan 🇧🇷🇪🇸 profil fotoğrafı
Rafaell Lycan 🇧🇷🇪🇸1 yıl önce

Hey mate 👋 Isn't that what tRPC does under the hood? Valid points btw 👏 cc @alexdotjs

TheFullStackSnack profil fotoğrafı
TheFullStackSnack1 yıl önce

You don't query db in server components if you don't have server components. Problem solved.

Ramon Malcolm profil fotoğrafı
Ramon Malcolm1 yıl önce

server-only is a package correct?

Mubashir profil fotoğrafı
Mubashir1 yıl önce

valid point 👍

rohan profil fotoğrafı
rohan1 yıl önce

Won’t the build fail if you query the DB in a client component

Alex Sidorenko profil fotoğrafı
Alex Sidorenko1 yıl önce

Not if it's a dynamic route (app/note/[id]/page.tsx), as those are not generated during the build time

Benzer Videolar