03 / 06

What are Server Functions?

Server Functions allow Client Components to call async functions executed on the server.

  1. 1

    When a Server Functions is defined with the 'use server' directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result.

  2. 2

    Server Functions can be created in Server Components and passed as props to Client Components, or they can be imported and used in Client Components.

Server Components can define Server Functions with the 'use server' directive:
When React renders the EmptyNote Server Function, it will create a reference to the createNoteAction function, and pass that reference to the Button Client Component. When the button is clicked, React will send a request to the server to execute the createNoteAction function with the reference provided:
Difficulty: 2/10
Topics: Cloud Computing, Serverless Architecture

Follow-up Questions

  • What are the benefits of using server functions?
  • How do server functions differ from traditional server-based applications?
  • What are some common use cases for server functions?