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
feat: Inherit messages by default in NextIntlClientProvider (#1682)
This makes it easier to get started. If you don't want this behavior,
you can still opt-out via `messages={null}`.
**TODO**
- [ ] Merge #1684 along with
this
Copy file name to clipboardexpand all lines: docs/src/pages/docs/environments/server-client-components.mdx
+6-12
Original file line number
Diff line number
Diff line change
@@ -115,11 +115,13 @@ Regarding performance, async functions and hooks can be used interchangeably. Th
115
115
116
116
## Using internationalization in Client Components
117
117
118
-
Depending on your situation, you may need to handle internationalization in Client Components. While providing all messages to the client side is typically the easiest way to [get started](/docs/getting-started/app-router#layout) and a reasonable approach for many apps, you can be more selective about which messages are passed to the client side if you're interested in optimizing the performance of your app.
118
+
Depending on your situation, you may need to handle internationalization in Client Components. Providing all messages to the client side is the easiest way to get started, therefore `next-intl` automatically does this when you render [`NextIntlClientProvider`](/docs/usage/configuration#nextintlclientprovider). This is a reasonable approach for many apps.
119
+
120
+
However, you can be more selective about which messages are passed to the client side if you're interested in optimizing the performance of your app.
119
121
120
122
There are several options for using translations from `next-intl` in Client Components, listed here in order of enabling the best performance:
121
123
122
-
### Option 1: Passing translations to Client Components
124
+
### Option 1: Passing translated labels to Client Components
123
125
124
126
The preferred approach is to pass the processed labels as props or `children` from a Server Component.
125
127
@@ -278,8 +280,6 @@ In particular, page and search params are often a great option because they offe
278
280
279
281
### Option 3: Providing individual messages
280
282
281
-
To reduce bundle size, `next-intl` doesn't automatically provide [messages](/docs/usage/configuration#messages) to Client Components.
282
-
283
283
If you need to incorporate dynamic state into components that can not be moved to the server side, you can wrap these components with `NextIntlClientProvider` and provide the relevant messages.
284
284
285
285
```tsx filename="Counter.tsx"
@@ -315,22 +315,16 @@ An automatic, compiler-driven approach is being evaluated in [`next-intl#1`](htt
315
315
316
316
### Option 4: Providing all messages
317
317
318
-
If you're building a highly dynamic app where most components use React's interactive features, you may prefer to make all messages available to Client Components.
318
+
If you're building a highly dynamic app where most components use React's interactive features, you may prefer to make all messages available to Client Components—this is the default behavior of `next-intl`.
These props are inherited if you're rendering `NextIntlClientProvider` from a Server Component:
77
75
78
76
1.`locale`
79
-
2.`now`
80
-
3.`timeZone`
81
-
4.`formats`
77
+
2.`messages`
78
+
3.`now`
79
+
4.`timeZone`
80
+
5.`formats`
82
81
83
82
In contrast, these props can be provided as necessary:
84
83
85
-
1.`messages` (see [Internationalization in Client Components](/docs/environments/server-client-components#using-internationalization-in-client-components))
86
-
2.`onError` and `getMessageFallback`
84
+
1.`onError`
85
+
2.`getMessageFallback`
87
86
88
87
Additionally, nested instances of `NextIntlClientProvider` will inherit configuration from their respective ancestors. Note however that individual props are treated as atomic, therefore e.g. `messages` need to be merged manually—if necessary.
89
88
@@ -115,17 +114,16 @@ Once you have defined your client-side provider component, you can use it in a S
0 commit comments