{"success":true,"name":"fetch-data-in-next-js-server-components-not-useeffect","description":"In a Next.js App Router page and about to fetch data with useEffect","category":"ai-brimind","path":"ai-brimind/fetch-data-in-next-js-server-components-not-useeffect/SKILL.md","file":"SKILL.md","content":"---\nname: fetch-data-in-next-js-server-components-not-useeffect\ndescription: \"In a Next.js App Router page and about to fetch data with useEffect\"\n---\n\n# Fetch Data in Next.js Server Components, Not useEffect\n\n## When to use\nProject is Next.js App Router, and you are about to add useEffect + useState (or a client-side fetch) just to load data for a page or component.\n\n## Example request\nuseEffect fetch with a loading spinner for the main page data → the page could await the data on the server and arrive already filled. — Server Component data fetching. | copying the fetched result into useState and syncing it → the server already owns that data; the copy will drift. — Wrong data owner. | secret API key needed for the fetch → in a client fetch it leaks to the browser; on the server it stays hidden. — Server-only secrets. | data must update when the user clicks a filter → that is real client interactivity; a client fetch or a route with searchParams fits. — Interaction-driven fetch is the exception.\n\n## Instructions\nAct like a reviewer who blocks every useEffect data fetch in Next.js until it is proven necessary. Before writing the fetch: 1) State clearly WHO needs the data and WHEN: is it needed to render the page the first time? If yes, fetch it directly in the async Server Component with await — no useEffect, no loading state juggling, no exposed keys. 2) Classify the case: initial page data → Server Component fetch; data that changes because the user interacts (typing, filtering, polling) → client fetch is allowed, but say why. 3) Check what Next.js already gives you before writing custom caching or loaders: fetch caching and revalidate options, loading.tsx for the loading UI, error.tsx for failures, searchParams for filter state in the URL. Custom client fetching code should be thin glue, used only where interaction truly demands it. 4) If you are not sure whether the data is 'initial render' or 'interaction driven', ask or trace the actual user flow instead of defaulting to useEffect out of habit. Only write the fetch once you have named the correct owner (server or client) and can explain why that owner is right — not just that useEffect 'works'.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #482\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}