Skip to content

Commit dd39588

Browse files
committed
use client intro
1 parent 798b9f8 commit dd39588

File tree

2 files changed

+3
-40
lines changed

2 files changed

+3
-40
lines changed

src/content/reference/react/use-client.md

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,17 @@ title: "'use client'"
44

55
<Note>
66

7-
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.
7+
هذه التوجيهات لازمة فقط إذا كنت [تستخدم RSC (مكونات الخادم)](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) أو تبني مكتبة متوافقة معها.
88

99
</Note>
1010

1111

1212
<Intro>
1313

14-
`'use client'` marks source files whose components execute on the client.
14+
`'use client'` تميز الملفات التي يتم تنفيذ مكوناتها من جانب العميل
1515

1616
</Intro>
1717

1818
<InlineToc />
1919

2020
---
21-
22-
## Reference {/*reference*/}
23-
24-
### `'use client'` {/*use-client*/}
25-
26-
Add `'use client';` at the very top of a file to mark that the file (including any child components it uses) executes on the client, regardless of where it's imported.
27-
28-
```js
29-
'use client';
30-
31-
import { useState } from 'react';
32-
33-
export default function RichTextEditor(props) {
34-
// ...
35-
```
36-
37-
When a file marked `'use client'` is imported from a server component, [compatible bundlers](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) will treat the import as the "cut-off point" between server-only code and client code. Components at or below this point in the module graph can use client-only React features like [`useState`](/reference/react/useState).
38-
39-
#### Caveats {/*caveats*/}
40-
41-
* It's not necessary to add `'use client'` to every file that uses client-only React features, only the files that are imported from server component files. `'use client'` denotes the _boundary_ between server-only and client code; any components further down the tree will automatically be executed on the client. In order to be rendered from server components, components exported from `'use client'` files must have serializable props.
42-
* When a `'use client'` file is imported from a server file, the imported values can be rendered as a React component or passed via props to a client component. Any other use will throw an exception.
43-
* When a `'use client'` file is imported from another client file, the directive has no effect. This allows you to write client-only components that are simultaneously usable from server and client components.
44-
* All the code in `'use client'` file as well as any modules it imports (directly or indirectly) will become a part of the client module graph and must be sent to and executed by the client in order to be rendered by the browser. To reduce client bundle size and take full advantage of the server, move state (and the `'use client'` directives) lower in the tree when possible, and pass rendered server components [as children](/learn/passing-props-to-a-component#passing-jsx-as-children) to client components.
45-
* Because props are serialized across the server–client boundary, note that the placement of these directives can affect the amount of data sent to the client; avoid data structures that are larger than necessary.
46-
* Components like a `<MarkdownRenderer>` that use neither server-only nor client-only features should generally not be marked with `'use client'`. That way, they can render exclusively on the server when used from a server component, but they'll be added to the client bundle when used from a client component.
47-
* Libraries published to npm should include `'use client'` on exported React components that can be rendered with serializable props that use client-only React features, to allow those components to be imported and rendered by server components. Otherwise, users will need to wrap library components in their own `'use client'` files which can be cumbersome and prevents the library from moving logic to the server later. When publishing prebundled files to npm, ensure that `'use client'` source files end up in a bundle marked with `'use client'`, separate from any bundle containing exports that can be used directly on the server.
48-
* Client components will still run as part of server-side rendering (SSR) or build-time static site generation (SSG), which act as clients to transform React components' initial render output to HTML that can be rendered before JavaScript bundles are downloaded. But they can't use server-only features like reading directly from a database.
49-
* Directives like `'use client'` must be at the very beginning of a file, above any imports or other code (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.)
50-
51-
## Usage {/*usage*/}
52-
53-
<Wip>
54-
55-
This section is incomplete. See also the [Next.js documentation for Server Components](https://beta.nextjs.org/docs/rendering/server-and-client-components).
56-
57-
</Wip>

src/content/reference/react/use-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ title: "'use server'"
2121

2222
---
2323

24-
## Reference {/*reference*/}
24+
## المرجع {/*reference*/}
2525

2626
### `'use server'` {/*use-server*/}
2727

0 commit comments

Comments
 (0)