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: docs/pages/docs/environments/server-client-components.mdx
+83-2Lines changed: 83 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -127,7 +127,7 @@ Depending on your situation, you may need to handle internationalization in Clie
127
127
128
128
The preferred approach is to pass the processed labels as props or `children` from a Server Component.
129
129
130
-
```tsx filename="[locale]/faq/page.tsx"
130
+
```tsx filename="[locale]/faq/page.tsx" {10-12}
131
131
import {useTranslations} from'next-intl';
132
132
importExpandablefrom'./Expandable';
133
133
@@ -165,10 +165,91 @@ function Expandable({title, children}) {
165
165
}
166
166
```
167
167
168
-
As you see, we can use interactive features from React like `useState` on translated content, even though the translation only runs on the server side.
168
+
By doing this, we can use interactive features from React like `useState` on translated content, even though the translation only runs on the server side.
169
169
170
170
Learn more in the Next.js docs: [Passing Server Components to Client Components as Props](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#supported-pattern-passing-server-components-to-client-components-as-props)
171
171
172
+
<details>
173
+
<summary>Example: How can I implement a form?</summary>
174
+
175
+
Forms need client-side state for showing loading indicators and validation errors.
176
+
177
+
To keep internationalization on the server side, it can be helpful to structure your components in a way where the interactive parts are moved out to leaf components instead of marking the whole form with `'use client';`.
178
+
179
+
**Example:**
180
+
181
+
```tsx filename="app/register/page.tsx"
182
+
import {useTranslations} from'next-intl';
183
+
184
+
// A Client Component, so that it can use `useFormState` to
185
+
// potentially display errors received after submission.
186
+
importRegisterFormfrom'./RegisterForm';
187
+
188
+
// A Client Component, so that it can use `useFormStatus`
189
+
// to disable the input field during submission.
190
+
importFormFieldfrom'./FormField';
191
+
192
+
// A Client Component, so that it can use `useFormStatus`
193
+
// to disable the submit button during submission.
<summary>Example: How can I implement a locale switcher?</summary>
220
+
221
+
If you implement a locale switcher as an interactive select, you can keep internationalization on the server side by rendering the labels from a Server Component and only marking the select element as a Client Component.
0 commit comments