directive
A string written at the top of a file or function, such as 'use client', that tells React or Next.js how to treat that code.
In more detail
Directives must come before any imports or other code in the file or function. Tools read them at build time to decide where the code may run or how it is treated.
Example
React defines 'use client' and 'use server'; Next.js adds 'use cache'.Related terms
- 'use client' — The directive that marks a module as the entry point to client code, so it and its imports are sent to the browser.
- 'use server' — The directive that marks async functions as Server Actions, callable from the client but always run on the server.
- 'use cache' — A Next.js directive that caches the result of a function, component or whole route, with its arguments forming the cache key.
Taught in
- Client Components: use client & Hydration Models — Next.js 15 & Modern App Router Architecture
- Component Tree Composition: Interleaving RSC & Client — Next.js 15 & Modern App Router Architecture
- Error Boundaries: Nested error.tsx & Reset Logic — Next.js 15 & Modern App Router Architecture
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Server Actions: use server Directives & Mutations — Next.js 15 & Modern App Router Architecture
- Revalidation Strategies: revalidatePath & Cache Life — Next.js 15 & Modern App Router Architecture