Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

Do not query db in server components

74,112 Aufrufe • vor 1 Jahr •via X (Twitter)

11 Kommentare

Profilbild von object Object
object Objectvor 1 Jahr

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)

Profilbild von Alex Sidorenko
Alex Sidorenkovor 1 Jahr

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.

Profilbild von MazrikBeats - check mes sons bg
MazrikBeats - check mes sons bgvor 1 Jahr

Or use tRPC

Profilbild von freddie
freddievor 1 Jahr

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

Profilbild von Alex Sidorenko
Alex Sidorenkovor 1 Jahr

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.

Profilbild von Rafaell Lycan 🇧🇷🇪🇸
Rafaell Lycan 🇧🇷🇪🇸vor 1 Jahr

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

Profilbild von TheFullStackSnack
TheFullStackSnackvor 1 Jahr

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

Profilbild von Ramon Malcolm
Ramon Malcolmvor 1 Jahr

server-only is a package correct?

Profilbild von Mubashir
Mubashirvor 1 Jahr

valid point 👍

Profilbild von rohan
rohanvor 1 Jahr

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

Profilbild von Alex Sidorenko
Alex Sidorenkovor 1 Jahr

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

Ähnliche Videos