Next.js
next/use-client-at-leaves
Keep App Router pages and layouts Server Components; put 'use client' on the small interactive component they render.
umiarkowanastatycznefe-nextjs
Dlaczego
'use client' marks a boundary: the file and everything it imports go into the browser bundle. On a page or layout that means the whole route's markup, its helpers and its libraries are downloaded and hydrated, data fetching moves to the client, and the file can no longer export metadata or generateMetadata.
Poprawka
Remove 'use client' from the page or layout. Move the state, effects and handlers into a component of their own (SearchBox, AddToCartButton) that starts with 'use client', and render it from the server page, passing data as serializable props. Server Components passed as children to a client component stay on the server.
Przykłady
// bad: app/products/page.tsx
'use client'
export default function Page() { const [q, setQ] = useState(''); return <main>…</main> }
// good: app/products/page.tsx stays a Server Component
export default async function Page() { const products = await getProducts(); return <main><SearchBox /><List items={products} /></main> }Źródła
Fakty
- Identyfikator
next/use-client-at-leaves- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
jsx- Tylko w projektach z
next- Uczy jej skill
fe-nextjsNext.js App Router- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain next/use-client-at-leaves