Skip to content

Commit 626ff7d

Browse files
authored
Revert formatting changes
1 parent 234a0cf commit 626ff7d

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

src/content/reference/rsc/server-functions.md

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Server Functions allow Client Components to call async functions executed on the
2020

2121
<Note>
2222

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*/}
2424

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.
2626

2727
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.
2828

@@ -32,48 +32,49 @@ When a Server Function is defined with the [`"use server"`](/reference/rsc/use-s
3232

3333
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.
3434

35-
## Usage {/* usage */}
35+
## Usage {/*usage*/}
3636

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*/}
3838

3939
Server Components can define Server Functions with the `"use server"` directive:
4040

4141
```js [[2, 7, "'use server'"], [1, 5, "createNoteAction"], [1, 12, "createNoteAction"]]
4242
// Server Component
4343
import Button from './Button';
4444

45-
function EmptyNote() {
45+
function EmptyNote () {
4646
async function createNoteAction() {
4747
// Server Function
4848
'use server';
49-
49+
5050
await db.notes.create();
5151
}
5252

53-
return <Button onClick={createNoteAction} />;
53+
return <Button onClick={createNoteAction}/>;
5454
}
5555
```
5656

5757
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:
5858

5959
```js {5}
60-
'use client';
60+
"use client";
6161

62-
export default function Button({onClick}) {
63-
console.log(onClick);
62+
export default function Button({onClick}) {
63+
console.log(onClick);
6464
// {$$typeof: Symbol.for("react.server.reference"), $$id: 'createNoteAction'}
65-
return <button onClick={() => onClick()}>Create Empty Note</button>;
65+
return <button onClick={() => onClick()}>Create Empty Note</button>
6666
}
6767
```
6868

6969
For more, see the docs for [`"use server"`](/reference/rsc/use-server).
7070

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*/}
7273

7374
Client Components can import Server Functions from files that use the `"use server"` directive:
7475

7576
```js [[1, 3, "createNote"]]
76-
'use server';
77+
"use server";
7778

7879
export async function createNote() {
7980
await db.notes.create();
@@ -83,24 +84,24 @@ export async function createNote() {
8384
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:
8485

8586
```js [[1, 2, "createNote"], [1, 5, "createNote"], [1, 7, "createNote"]]
86-
'use client';
87+
"use client";
8788
import {createNote} from './actions';
8889

8990
function EmptyNote() {
9091
console.log(createNote);
9192
// {$$typeof: Symbol.for("react.server.reference"), $$id: 'createNote'}
92-
<button onClick={() => createNote()} />;
93+
<button onClick={() => createNote()} />
9394
}
9495
```
9596

9697
For more, see the docs for [`"use server"`](/reference/rsc/use-server).
9798

98-
### Server Functions with Actions {/* server-functions-with-actions */}
99+
### Server Functions with Actions {/*server-functions-with-actions*/}
99100

100101
Server Functions can be called from Actions on the client:
101102

102103
```js [[1, 3, "updateName"]]
103-
'use server';
104+
"use server";
104105

105106
export async function updateName(name) {
106107
if (!name) {
@@ -111,7 +112,7 @@ export async function updateName(name) {
111112
```
112113

113114
```js [[1, 3, "updateName"], [1, 13, "updateName"], [2, 11, "submitAction"], [2, 23, "submitAction"]]
114-
'use client';
115+
"use client";
115116

116117
import {updateName} from './actions';
117118

@@ -129,30 +130,31 @@ function UpdateName() {
129130
} else {
130131
setName('');
131132
}
132-
});
133-
};
133+
134+
})
135+
}
134136

135137
return (
136138
<form action={submitAction}>
137-
<input type="text" name="name" disabled={isPending} />
139+
<input type="text" name="name" disabled={isPending}/>
138140
{error && <span>Failed: {error}</span>}
139141
</form>
140-
);
142+
)
141143
}
142144
```
143145

144146
This allows you to access the `isPending` state of the Server Function by wrapping it in an Action on the client.
145147

146148
For more, see the docs for [Calling a Server Function outside of `<form>`](/reference/rsc/use-server#calling-a-server-function-outside-of-form)
147149

148-
### Server Functions with Form Actions {/* using-server-functions-with-form-actions */}
150+
### Server Functions with Form Actions {/*using-server-functions-with-form-actions*/}
149151

150152
Server Functions work with the new Form features in React 19.
151153

152154
You can pass a Server Function to a Form to automatically submit the form to the server:
153155

154156
```js [[1, 3, "updateName"], [1, 7, "updateName"]]
155-
'use client';
157+
"use client";
156158

157159
import {updateName} from './actions';
158160

@@ -161,31 +163,29 @@ function UpdateName() {
161163
<form action={updateName}>
162164
<input type="text" name="name" />
163165
</form>
164-
);
166+
)
165167
}
166168
```
167169

168170
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.
169171

170172
For more, see the docs for [Server Functions in Forms](/reference/rsc/use-server#server-functions-in-forms).
171173

172-
### Server Functions with `useActionState` {/* server-functions-with-use-action-state */}
174+
### Server Functions with `useActionState` {/*server-functions-with-use-action-state*/}
173175

174176
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:
175177

176178
```js [[1, 3, "updateName"], [1, 6, "updateName"], [2, 6, "submitAction"], [2, 9, "submitAction"]]
177-
'use client';
179+
"use client";
178180

179181
import {updateName} from './actions';
180182

181183
function UpdateName() {
182-
const [state, submitAction, isPending] = useActionState(updateName, {
183-
error: null,
184-
});
184+
const [state, submitAction, isPending] = useActionState(updateName, {error: null});
185185

186186
return (
187187
<form action={submitAction}>
188-
<input type="text" name="name" disabled={isPending} />
188+
<input type="text" name="name" disabled={isPending}/>
189189
{state.error && <span>Failed: {state.error}</span>}
190190
</form>
191191
);
@@ -196,19 +196,23 @@ When using `useActionState` with Server Functions, React will also automatically
196196

197197
For more, see the docs for [`useActionState`](/reference/react/useActionState).
198198

199-
### Progressive enhancement with `useActionState` {/* progressive-enhancement-with-useactionstate */}
199+
### Progressive enhancement with `useActionState` {/*progressive-enhancement-with-useactionstate*/}
200200

201201
Server Functions also support progressive enhancement with the third argument of `useActionState`.
202202

203203
```js [[1, 3, "updateName"], [1, 6, "updateName"], [2, 6, "/name/update"], [3, 6, "submitAction"], [3, 9, "submitAction"]]
204-
'use client';
204+
"use client";
205205

206206
import {updateName} from './actions';
207207

208208
function UpdateName() {
209209
const [, submitAction] = useActionState(updateName, null, `/name/update`);
210210

211-
return <form action={submitAction}>...</form>;
211+
return (
212+
<form action={submitAction}>
213+
...
214+
</form>
215+
);
212216
}
213217
```
214218

0 commit comments

Comments
 (0)