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/react/use-server.md
+3-30Lines changed: 3 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,45 +4,18 @@ title: "'use server'"
4
4
5
5
<Wip>
6
6
7
-
This section is incomplete.
7
+
هذا القسم غير مكتمل بعد.
8
8
9
-
These directives are needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks)or building a library compatible with them.
9
+
هذه التوجيهات لازمة فقط إذا كنت [تستخدم RSC (مكونات الخادم)](/learn/start-a-new-react-project#bleeding-edge-react-frameworks)أو تبني مكتبة متوافقة معها.
10
10
11
11
</Wip>
12
12
13
13
14
14
<Intro>
15
15
16
-
`'use server'`marks server-side functions that can be called from client-side code.
16
+
`'use server'`يميّز دوال الخادم (server-side functions) التي يمكن استدعاؤها في الكود من جانب العميل (client-side).
17
17
18
18
</Intro>
19
19
20
20
<InlineToc />
21
21
22
-
---
23
-
24
-
## Reference {/*reference*/}
25
-
26
-
### `'use server'` {/*use-server*/}
27
-
28
-
Add `'use server';` at the very top of an async function to mark that the function can be executed by the client.
29
-
30
-
```js
31
-
asyncfunctionaddToCart(data) {
32
-
'use server';
33
-
// ...
34
-
}
35
-
36
-
// <ProductDetailPage addToCart={addToCart} />
37
-
```
38
-
39
-
This function can be passed to the client. When called on the client, it will make a network request to the server that includes a serialized copy of any arguments passed. If the server function returns a value, that value will be serialized and returned to the client.
40
-
41
-
Alternatively, add `'use server';` at the very top of a file to mark all exports within that file as async server functions that can be used anywhere, including imported in client component files.
42
-
43
-
#### Caveats {/*caveats*/}
44
-
45
-
* Remember that parameters to functions marked with `'use server'` are fully client-controlled. For security, always treat them as untrusted input, making sure to validate and escape the arguments as appropriate.
46
-
* To avoid the confusion that might result from mixing client- and server-side code in the same file, `'use server'` can only be used in server-side files; the resulting functions can be passed to client components through props.
47
-
* Because the underlying network calls are always asynchronous, `'use server'` can be used only on async functions.
48
-
* Directives like `'use server'` must be at the very beginning of their function or file, above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks. (The `'use xyz'` directive format somewhat resembles the `useXyz()` Hook naming convention, but the similarity is coincidental.)
0 commit comments