Next.js · Junior · Question 35 of 75
How do you load data in a server component?
- ✓Correct answer: Make the component
asyncand callawait fetch()or a DB query - 2Only via
useEffectanduseState, as in client React - 3Only via a Route Handler and a request to it from the client
Explanation
Server components can be async and access data directly - APIs, ORMs, the file system - without sending secrets to the browser. Calling your own Route Handler from a server component is an unnecessary network round trip. Hooks aren't available in server components.