Next.js Discord

Discord Forum

useEffect for fetching data vs fetching data in a server component and passing it as props

Unanswered
Field Sparrow posted this in #help-forum
Open in Discord
Field SparrowOP
the server component is importing the client component and using it

7 Replies

You simply can not use useEffect in a server component. If you want to use that hook, use it in a client component
Field SparrowOP
i never said ill use useEffect in a server component
my entire question is
useEffect in the client component to fetch its own data
or fetching in server component that uses the client component and passing the data as props to the client component
Knopper gall
You didn't even ask a question, but I assume you're asking which is preferable.

I would say server component wrapped in suspense for loading states if required. Reason being during development, useEffect is called twice, and you can get screen flicker as it only calls on page render
(also server components work when JS is disabled in the client)