Next.js mistakes: client components, useEffect, cache, secrets, API routes

5 Next.js mistakes that slow down your app (and confuse your team): 1. Adding "use client" to every component Server components exist for a reason. They're faster and ship less JavaScript. Only use client components when you need browser APIs or interactivity. 2. Still fetching data in useEffect Old React habit. In Next.js, fetch directly in server components. No loading state boilerplate. No client-side waterfall. 3. Fighting the cache instead of understanding it Next.js caches aggressively by default. If your data looks stale, it's probably cached. Learn how fetch cache, route cache, and router cache work - or spend hours debugging. 4. Exposing secrets in client components Only NEXT_PUBLIC_ env vars are meant for the browser. If you're using an API key in a client component, it's visible to anyone with dev tools. 5. Overusing API routes You don't need an API route to fetch data for your own app. Server components can fetch directly. Save API routes for webhooks and external integrations. Most of these are just unlearning old SPA patterns. Next.js works differently - lean into it. #WebDevelopment #NextJS #React #DevTips #BuildInPublic

Yes! In Next.js, every client component adds to the JS bundle, increasing its size. Server components improve performance because they render on the server and reduce the amount of JavaScript sent to the browser. Use client components only when interactivity is needed.

To view or add a comment, sign in

Explore content categories