Skip to content

Commit 234a0cf

Browse files
committed
fix(docs): corrected broken link in server-functions.md
1 parent e9a7cb1 commit 234a0cf

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

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

Lines changed: 37 additions & 42 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,77 +32,75 @@ 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-
72-
### Importing Server Functions from Client Components {/*importing-server-functions-from-client-components*/}
71+
### Importing Server Functions from Client Components {/* importing-server-functions-from-client-components */}
7372

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

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

7978
export async function createNote() {
8079
await db.notes.create();
8180
}
82-
8381
```
8482

8583
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:
8684

8785
```js [[1, 2, "createNote"], [1, 5, "createNote"], [1, 7, "createNote"]]
88-
"use client";
86+
'use client';
8987
import {createNote} from './actions';
9088

9189
function EmptyNote() {
9290
console.log(createNote);
9391
// {$$typeof: Symbol.for("react.server.reference"), $$id: 'createNote'}
94-
<button onClick={() => createNote()} />
92+
<button onClick={() => createNote()} />;
9593
}
9694
```
9795

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

100-
### Server Functions with Actions {/*server-functions-with-actions*/}
98+
### Server Functions with Actions {/* server-functions-with-actions */}
10199

102100
Server Functions can be called from Actions on the client:
103101

104102
```js [[1, 3, "updateName"]]
105-
"use server";
103+
'use server';
106104

107105
export async function updateName(name) {
108106
if (!name) {
@@ -113,7 +111,7 @@ export async function updateName(name) {
113111
```
114112

115113
```js [[1, 3, "updateName"], [1, 13, "updateName"], [2, 11, "submitAction"], [2, 23, "submitAction"]]
116-
"use client";
114+
'use client';
117115

118116
import {updateName} from './actions';
119117

@@ -131,31 +129,30 @@ function UpdateName() {
131129
} else {
132130
setName('');
133131
}
134-
})
135-
}
136-
132+
});
133+
};
134+
137135
return (
138136
<form action={submitAction}>
139-
<input type="text" name="name" disabled={isPending}/>
137+
<input type="text" name="name" disabled={isPending} />
140138
{error && <span>Failed: {error}</span>}
141139
</form>
142-
)
140+
);
143141
}
144142
```
145143

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

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

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

152150
Server Functions work with the new Form features in React 19.
153151

154152
You can pass a Server Function to a Form to automatically submit the form to the server:
155153

156-
157154
```js [[1, 3, "updateName"], [1, 7, "updateName"]]
158-
"use client";
155+
'use client';
159156

160157
import {updateName} from './actions';
161158

@@ -164,29 +161,31 @@ function UpdateName() {
164161
<form action={updateName}>
165162
<input type="text" name="name" />
166163
</form>
167-
)
164+
);
168165
}
169166
```
170167

171168
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.
172169

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

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

177174
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:
178175

179176
```js [[1, 3, "updateName"], [1, 6, "updateName"], [2, 6, "submitAction"], [2, 9, "submitAction"]]
180-
"use client";
177+
'use client';
181178

182179
import {updateName} from './actions';
183180

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

187186
return (
188187
<form action={submitAction}>
189-
<input type="text" name="name" disabled={isPending}/>
188+
<input type="text" name="name" disabled={isPending} />
190189
{state.error && <span>Failed: {state.error}</span>}
191190
</form>
192191
);
@@ -195,28 +194,24 @@ function UpdateName() {
195194

196195
When using `useActionState` with Server Functions, React will also automatically replay form submissions entered before hydration finishes. This means users can interact with your app even before the app has hydrated.
197196

198-
For more, see the docs for [`useActionState`](/reference/react-dom/hooks/useFormState).
197+
For more, see the docs for [`useActionState`](/reference/react/useActionState).
199198

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

202201
Server Functions also support progressive enhancement with the third argument of `useActionState`.
203202

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

207206
import {updateName} from './actions';
208207

209208
function UpdateName() {
210209
const [, submitAction] = useActionState(updateName, null, `/name/update`);
211210

212-
return (
213-
<form action={submitAction}>
214-
...
215-
</form>
216-
);
211+
return <form action={submitAction}>...</form>;
217212
}
218213
```
219214

220215
When the <CodeStep step={2}>permalink</CodeStep> is provided to `useActionState`, React will redirect to the provided URL if the form is submitted before the JavaScript bundle loads.
221216

222-
For more, see the docs for [`useActionState`](/reference/react-dom/hooks/useFormState).
217+
For more, see the docs for [`useActionState`](/reference/react/useActionState).

0 commit comments

Comments
 (0)