You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/rsc/server-functions.md
+38-34Lines changed: 38 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,9 @@ Server Functions allow Client Components to call async functions executed on the
20
20
21
21
<Note>
22
22
23
-
#### How do I build support for Server Functions? {/*how-do-i-build-support-for-server-functions*/}
23
+
#### How do I build support for Server Functions? {/*how-do-i-build-support-for-server-functions*/}
24
24
25
-
While Server Functions in React 19 are stable and will not break between minor versions, the underlying APIs used to implement Server Functions in a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x.
25
+
While Server Functions in React 19 are stable and will not break between minor versions, the underlying APIs used to implement Server Functions in a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x.
26
26
27
27
To support Server Functions as a bundler or framework, we recommend pinning to a specific React version, or using the Canary release. We will continue working with bundlers and frameworks to stabilize the APIs used to implement Server Functions in the future.
28
28
@@ -32,48 +32,49 @@ When a Server Function is defined with the [`"use server"`](/reference/rsc/use-s
32
32
33
33
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.
34
34
35
-
## Usage {/*usage*/}
35
+
## Usage {/*usage*/}
36
36
37
-
### Creating a Server Function from a Server Component {/*creating-a-server-function-from-a-server-component*/}
37
+
### Creating a Server Function from a Server Component {/*creating-a-server-function-from-a-server-component*/}
38
38
39
39
Server Components can define Server Functions with the `"use server"` directive:
When React renders the `EmptyNote` Server Component, 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:
For more, see the docs for [`"use server"`](/reference/rsc/use-server).
70
70
71
-
### Importing Server Functions from Client Components {/* importing-server-functions-from-client-components */}
71
+
72
+
### Importing Server Functions from Client Components {/*importing-server-functions-from-client-components*/}
72
73
73
74
Client Components can import Server Functions from files that use the `"use server"` directive:
74
75
75
76
```js [[1, 3, "createNote"]]
76
-
'use server';
77
+
"use server";
77
78
78
79
exportasyncfunctioncreateNote() {
79
80
awaitdb.notes.create();
@@ -83,24 +84,24 @@ export async function createNote() {
83
84
When the bundler builds the `EmptyNote` Client Component, it will create a reference to the `createNote` function in the bundle. When the `button` is clicked, React will send a request to the server to execute the `createNote` function using the reference provided:
When the Form submission succeeds, React will automatically reset the form. You can add `useActionState` to access the pending state, last response, or to support progressive enhancement.
169
171
170
172
For more, see the docs for [Server Functions in Forms](/reference/rsc/use-server#server-functions-in-forms).
171
173
172
-
### Server Functions with `useActionState` {/*server-functions-with-use-action-state*/}
174
+
### Server Functions with `useActionState` {/*server-functions-with-use-action-state*/}
173
175
174
176
You can call Server Functions with `useActionState` for the common case where you just need access to the action pending state and last returned response:
0 commit comments