new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js · API reference · all subjects

directives: use client

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

'use client' directive creates client entry point

The 'use client' directive is defined by React and creates a client entry point from Server Components. It must appear at the top of a file before any imports, and it applies to the entire module and defines a file-wide boundary because the module is bundled and shipped to the browser. You cannot use 'use client' inline.

'use client' marks boundary and requires serializable props

'use client' marks its exports as the boundary between server and client. Client Component props that cross the boundary must be serializable. Ordinary functions, such as event handlers, cannot cross, but Server Functions can cross as references.

use client directive placement

The 'use client' directive must be placed at the top of the file, before any imports, to declare an entry point for Client Components.

use client defines server-client boundary

The 'use client' directive defines the server and client boundary. Components exported from a file with 'use client' serve as entry points to the client.

When to add use client directive

You do not need to add the 'use client' directive to every file that contains Client Components. You only need to add it to files whose components you want to render directly within Server Components.

use client directive purpose

The 'use client' directive declares an entry point for components to be rendered on the client side and should be used when creating interactive user interfaces that require client-side JavaScript capabilities, such as state management, event handling, and access to browser APIs. This is a React feature.

Client Component props must be serializable

When using the 'use client' directive, the props of the Client Components must be serializable. This means the props need to be in a format that React can serialize when sending data from the server to the client. Function props are not serializable.

Nesting Client Components within Server Components

Client Components can be nested within Server Components. Server Components handle static content, data fetching, and SEO-friendly elements. Client Components handle interactive elements that require state, effects, or browser APIs. This composition allows applications to be both performant and interactive.

use client example with Counter component

'use client' import { useState } from 'react' export default function Counter() { const [count, setCount] = useState(0) return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> </div> ) } This example shows how to create a Client Component with state management using the 'use client' directive at the top of the file.

Give your agent this brain