14 hours ago
- 'use client' and 'use server' directives abstract over sending code to the client (as script) and communicating back (as fetch), making the client/server boundary syntactic within the module system.
- 'use server' allows server functions to be exported and called from the client as async HTTP calls, providing a typed, statically analyzable RPC mechanism.
- 'use client' allows server code to import client components as references that become <script> tags, with optional server-side prerendering for initial HTML.
- Together, these directives enable modeling a client/server application as a single program spanning two environments, with type safety, dead code analysis, and reusable abstractions.
- The directives are not React-specific; they represent a paradigm similar to structured programming or async/await, expressing the network gap at the module level.
- Neither directive executes code on import; they only provide references (client reference or async function) that bridge the two runtime environments.