@intlayer/docs 5.7.6 → 5.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/generated/docs.entry.cjs +44 -238
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +44 -238
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -2
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_tanstack.md +457 -0
- package/docs/ar/packages/next-intlayer/index.md +0 -1
- package/docs/ar/packages/react-intlayer/index.md +0 -1
- package/docs/de/intlayer_with_tanstack.md +458 -0
- package/docs/de/packages/next-intlayer/index.md +0 -1
- package/docs/de/packages/react-intlayer/index.md +0 -1
- package/docs/en/intlayer_with_tanstack.md +452 -0
- package/docs/en/packages/next-intlayer/index.md +0 -1
- package/docs/en/packages/react-intlayer/index.md +0 -1
- package/docs/en-GB/intlayer_with_tanstack.md +457 -0
- package/docs/en-GB/packages/next-intlayer/index.md +0 -1
- package/docs/en-GB/packages/react-intlayer/index.md +0 -1
- package/docs/es/intlayer_with_tanstack.md +435 -0
- package/docs/es/packages/next-intlayer/index.md +0 -1
- package/docs/es/packages/react-intlayer/index.md +0 -1
- package/docs/fr/intlayer_with_tanstack.md +435 -0
- package/docs/fr/packages/next-intlayer/index.md +0 -1
- package/docs/fr/packages/react-intlayer/index.md +0 -1
- package/docs/hi/intlayer_with_tanstack.md +438 -0
- package/docs/hi/packages/next-intlayer/index.md +0 -1
- package/docs/hi/packages/react-intlayer/index.md +0 -1
- package/docs/it/intlayer_with_tanstack.md +457 -0
- package/docs/it/packages/next-intlayer/index.md +0 -1
- package/docs/it/packages/react-intlayer/index.md +0 -1
- package/docs/ja/intlayer_with_tanstack.md +457 -0
- package/docs/ja/packages/next-intlayer/index.md +0 -1
- package/docs/ja/packages/react-intlayer/index.md +0 -1
- package/docs/ko/intlayer_with_tanstack.md +457 -0
- package/docs/ko/packages/next-intlayer/index.md +0 -1
- package/docs/ko/packages/react-intlayer/index.md +0 -1
- package/docs/pt/intlayer_with_tanstack.md +457 -0
- package/docs/pt/packages/next-intlayer/index.md +0 -1
- package/docs/pt/packages/react-intlayer/index.md +0 -1
- package/docs/ru/intlayer_with_tanstack.md +458 -0
- package/docs/ru/packages/next-intlayer/index.md +0 -1
- package/docs/ru/packages/react-intlayer/index.md +0 -1
- package/docs/zh/intlayer_with_tanstack.md +435 -0
- package/docs/zh/packages/next-intlayer/index.md +0 -1
- package/docs/zh/packages/react-intlayer/index.md +0 -1
- package/package.json +9 -9
- package/src/generated/docs.entry.ts +44 -238
- package/docs/ar/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/ar/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/de/packages/next-intlayer/useIntlayerAsync.md +0 -262
- package/docs/de/packages/react-intlayer/useIntlayerAsync.md +0 -256
- package/docs/en/packages/next-intlayer/useIntlayerAsync.md +0 -239
- package/docs/en/packages/react-intlayer/useIntlayerAsync.md +0 -254
- package/docs/en-GB/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/en-GB/packages/react-intlayer/useIntlayerAsync.md +0 -257
- package/docs/es/packages/next-intlayer/useIntlayerAsync.md +0 -240
- package/docs/es/packages/react-intlayer/useIntlayerAsync.md +0 -276
- package/docs/fr/packages/next-intlayer/useIntlayerAsync.md +0 -238
- package/docs/fr/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/hi/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/hi/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/it/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/it/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/ja/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/ja/packages/react-intlayer/useIntlayerAsync.md +0 -268
- package/docs/ko/packages/next-intlayer/useIntlayerAsync.md +0 -260
- package/docs/ko/packages/react-intlayer/useIntlayerAsync.md +0 -271
- package/docs/pt/packages/next-intlayer/useIntlayerAsync.md +0 -238
- package/docs/pt/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/ru/packages/next-intlayer/useIntlayerAsync.md +0 -237
- package/docs/ru/packages/react-intlayer/useIntlayerAsync.md +0 -252
- package/docs/zh/packages/next-intlayer/useIntlayerAsync.md +0 -239
- package/docs/zh/packages/react-intlayer/useIntlayerAsync.md +0 -257
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
createdAt: 2024-08-11
|
|
3
|
-
updatedAt: 2025-06-29
|
|
4
|
-
title: useIntlayerAsync Hook Documentation | react-intlayer
|
|
5
|
-
description: See how to use the useIntlayerAsync hook for react-intlayer package
|
|
6
|
-
keywords:
|
|
7
|
-
- useIntlayerAsync
|
|
8
|
-
- dictionary
|
|
9
|
-
- key
|
|
10
|
-
- Intlayer
|
|
11
|
-
- Internationalization
|
|
12
|
-
- Documentation
|
|
13
|
-
- Next.js
|
|
14
|
-
- JavaScript
|
|
15
|
-
- React
|
|
16
|
-
slugs:
|
|
17
|
-
- doc
|
|
18
|
-
- packages
|
|
19
|
-
- react-intlayer
|
|
20
|
-
- useIntlayerAsync
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
# React Integration: `useIntlayerAsync` Hook Documentation
|
|
24
|
-
|
|
25
|
-
The `useIntlayerAsync` hook extends the functionality of `useIntlayer` by not only returning pre-rendered dictionaries but also fetching updates asynchronously, making it ideal for applications that frequently update their localized content after the initial render.
|
|
26
|
-
|
|
27
|
-
## Overview
|
|
28
|
-
|
|
29
|
-
- **Asynchronous Dictionary Loading:**
|
|
30
|
-
On initial mount, `useIntlayerAsync` first returns any pre-fetched or statically bundled locale dictionary (just like `useIntlayer` would) and then asynchronously fetches and merges any newly available remote dictionaries.
|
|
31
|
-
- **Progress State Management:**
|
|
32
|
-
The hook also provides an `isLoading` state, indicating when a remote dictionary is being fetched. This allows developers to display loading indicators or skeleton states for a smoother user experience.
|
|
33
|
-
|
|
34
|
-
## Environment Setup
|
|
35
|
-
|
|
36
|
-
Intlayer provides a headless Content Source Management (CSM) system that empowers non-developers to manage and update application content seamlessly. By using Intlayer’s intuitive dashboard, your team can edit localized text, images, and other resources without directly modifying code. This streamlines the content management process, fosters collaboration, and ensures that updates can be made quickly and easily.
|
|
37
|
-
|
|
38
|
-
To get started with Intlayer:
|
|
39
|
-
|
|
40
|
-
1. **Register and obtain an access token** at [https://intlayer.org/dashboard](https://intlayer.org/dashboard).
|
|
41
|
-
2. **Add credentials to your configuration file:**
|
|
42
|
-
In your React project, configure the Intlayer client with your credentials:
|
|
43
|
-
|
|
44
|
-
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
45
|
-
import type { IntlayerConfig } from "intlayer";
|
|
46
|
-
|
|
47
|
-
export default {
|
|
48
|
-
// ...
|
|
49
|
-
editor: {
|
|
50
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
51
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
52
|
-
},
|
|
53
|
-
} satisfies IntlayerConfig;
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
57
|
-
import { type IntlayerConfig } from "intlayer";
|
|
58
|
-
|
|
59
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
60
|
-
const config = {
|
|
61
|
-
// ...
|
|
62
|
-
editor: {
|
|
63
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
64
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export default config;
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
72
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
73
|
-
const config = {
|
|
74
|
-
// ...
|
|
75
|
-
editor: {
|
|
76
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
77
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
module.exports = config;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
3. **Push a new locale dictionary to Intlayer:**
|
|
85
|
-
|
|
86
|
-
```bash
|
|
87
|
-
npx intlayer dictionary push -d my-first-dictionary-key
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
This command uploads your initial content dictionaries, making them available for asynchronous fetching and editing through the Intlayer platform.
|
|
91
|
-
|
|
92
|
-
## Importing `useIntlayerAsync` in React
|
|
93
|
-
|
|
94
|
-
In your React components, import `useIntlayerAsync`:
|
|
95
|
-
|
|
96
|
-
```ts codeFormat="typescript"
|
|
97
|
-
import { useIntlayerAsync } from "react-intlayer";
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
```js codeFormat="esm"
|
|
101
|
-
import { useIntlayerAsync } from "react-intlayer";
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
```js codeFormat="commonjs"
|
|
105
|
-
const { useIntlayerAsync } = require("react-intlayer");
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Parameters
|
|
109
|
-
|
|
110
|
-
1. **`key`**:
|
|
111
|
-
**Type**: `DictionaryKeys`
|
|
112
|
-
The dictionary key used to identify the localized content block. This key should be defined in your content declaration files.
|
|
113
|
-
|
|
114
|
-
2. **`locale`** (optional):
|
|
115
|
-
**Type**: `Locales`
|
|
116
|
-
The specific locale you want to target. If omitted, the hook uses the locale from the current Intlayer context.
|
|
117
|
-
|
|
118
|
-
3. **`isRenderEditor`** (optional, defaults to `true`):
|
|
119
|
-
**Type**: `boolean`
|
|
120
|
-
Determines whether the content should be ready for rendering with the Intlayer editor overlay. If set to `false`, the returned dictionary data will exclude editor-specific features.
|
|
121
|
-
|
|
122
|
-
## Return Value
|
|
123
|
-
|
|
124
|
-
The hook returns a dictionary object containing localized content keyed by `key` and `locale`. It also includes an `isLoading` boolean indicating whether a remote dictionary is currently being fetched.
|
|
125
|
-
|
|
126
|
-
## Example Usage in a React Component
|
|
127
|
-
|
|
128
|
-
```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript"
|
|
129
|
-
import { useEffect, type FC } from "react";
|
|
130
|
-
import { useIntlayerAsync } from "react-intlayer";
|
|
131
|
-
|
|
132
|
-
export const ComponentExample: FC = () => {
|
|
133
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
134
|
-
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
if (isLoading) {
|
|
137
|
-
console.log("Content is loading...");
|
|
138
|
-
}
|
|
139
|
-
}, [isLoading]);
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<div>
|
|
143
|
-
{isLoading ? (
|
|
144
|
-
<div>
|
|
145
|
-
<h1>Loading…</h1>
|
|
146
|
-
<p>Please wait while content updates.</p>
|
|
147
|
-
</div>
|
|
148
|
-
) : (
|
|
149
|
-
<div>
|
|
150
|
-
<h1>{title.value}</h1>
|
|
151
|
-
<p>{description.value}</p>
|
|
152
|
-
</div>
|
|
153
|
-
)}
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
```jsx fileName="src/components/ComponentExample.mjx" codeFormat="esm"
|
|
160
|
-
import { useEffect } from "react";
|
|
161
|
-
import { useIntlayerAsync } from "react-intlayer";
|
|
162
|
-
|
|
163
|
-
const ComponentExample = () => {
|
|
164
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
165
|
-
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
if (isLoading) {
|
|
168
|
-
console.log("Content is loading...");
|
|
169
|
-
}
|
|
170
|
-
}, [isLoading]);
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<div>
|
|
174
|
-
{isLoading ? (
|
|
175
|
-
<div>
|
|
176
|
-
<h1>Loading…</h1>
|
|
177
|
-
<p>Please wait while content updates.</p>
|
|
178
|
-
</div>
|
|
179
|
-
) : (
|
|
180
|
-
<div>
|
|
181
|
-
<h1>{title.value}</h1>
|
|
182
|
-
<p>{description.value}</p>
|
|
183
|
-
</div>
|
|
184
|
-
)}
|
|
185
|
-
</div>
|
|
186
|
-
);
|
|
187
|
-
};
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
```jsx fileName="src/components/ComponentExample.csx" codeFormat="commonjs"
|
|
191
|
-
const { useEffect } = require("react");
|
|
192
|
-
const { useIntlayerAsync } = require("react-intlayer");
|
|
193
|
-
|
|
194
|
-
const ComponentExample = () => {
|
|
195
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
196
|
-
|
|
197
|
-
useEffect(() => {
|
|
198
|
-
if (isLoading) {
|
|
199
|
-
console.log("Content is loading...");
|
|
200
|
-
}
|
|
201
|
-
}, [isLoading]);
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
<div>
|
|
205
|
-
{isLoading ? (
|
|
206
|
-
<div>
|
|
207
|
-
<h1>Loading…</h1>
|
|
208
|
-
<p>Please wait while content updates.</p>
|
|
209
|
-
</div>
|
|
210
|
-
) : (
|
|
211
|
-
<div>
|
|
212
|
-
<h1>{title.value}</h1>
|
|
213
|
-
<p>{description.value}</p>
|
|
214
|
-
</div>
|
|
215
|
-
)}
|
|
216
|
-
</div>
|
|
217
|
-
);
|
|
218
|
-
};
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
**Key Points:**
|
|
222
|
-
|
|
223
|
-
- On initial render, `title` and `description` come from the pre-fetched or statically embedded locale dictionary.
|
|
224
|
-
- While `isLoading` is `true`, a background request fetches an updated dictionary.
|
|
225
|
-
- Once the fetch completes, `title` and `description` are updated with the newest content, and `isLoading` returns to `false`.
|
|
226
|
-
|
|
227
|
-
## Handling Attribute Localization
|
|
228
|
-
|
|
229
|
-
You can also retrieve localized attribute values for various HTML properties (e.g., `alt`, `title`, `aria-label`):
|
|
230
|
-
|
|
231
|
-
```jsx
|
|
232
|
-
<img src={title.image.src.value} alt={title.image.alt.value} />
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
## Dictionary Files
|
|
236
|
-
|
|
237
|
-
All content keys must be defined in your content declaration files for type safety and to prevent runtime errors. These files enable TypeScript validation, ensuring you always reference existing keys and locales.
|
|
238
|
-
|
|
239
|
-
Instructions for setting up content declaration files are available [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/get_started.md).
|
|
240
|
-
|
|
241
|
-
## Further Information
|
|
242
|
-
|
|
243
|
-
- **Intlayer Visual Editor:**
|
|
244
|
-
Integrate with the Intlayer visual editor for managing and editing content directly from the UI. More details [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_visual_editor.md).
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
**In summary**, `useIntlayerAsync` is a powerful React hook designed to enhance the user experience and maintain content freshness by merging pre-rendered or pre-fetched dictionaries with asynchronous dictionary updates. By leveraging `isLoading` and TypeScript-based content declarations, you can seamlessly integrate dynamic, localized content into your React applications.
|
|
249
|
-
|
|
250
|
-
## Doc History
|
|
251
|
-
|
|
252
|
-
| Version | Date | Changes |
|
|
253
|
-
| ------- | ---------- | ------------ |
|
|
254
|
-
| 5.5.10 | 2025-06-29 | Init history |
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
createdAt: 2024-08-11
|
|
3
|
-
updatedAt: 2025-06-29
|
|
4
|
-
title: useIntlayerAsync Hook Documentation | next-intlayer
|
|
5
|
-
description: See how to use the useIntlayerAsync hook for next-intlayer package
|
|
6
|
-
keywords:
|
|
7
|
-
- useIntlayerAsync
|
|
8
|
-
- dictionary
|
|
9
|
-
- key
|
|
10
|
-
- Intlayer
|
|
11
|
-
- Internationalisation
|
|
12
|
-
- Documentation
|
|
13
|
-
- Next.js
|
|
14
|
-
- JavaScript
|
|
15
|
-
- React
|
|
16
|
-
slugs:
|
|
17
|
-
- doc
|
|
18
|
-
- packages
|
|
19
|
-
- next-intlayer
|
|
20
|
-
- useIntlayerAsync
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
# Next.js Integration: `useIntlayerAsync` Hook Documentation
|
|
24
|
-
|
|
25
|
-
The `useIntlayerAsync` hook extends the functionality of `useIntlayer` by not only returning pre-rendered dictionaries but also fetching updates asynchronously, making it ideal for applications that frequently update their localised content after the initial render.
|
|
26
|
-
|
|
27
|
-
## Overview
|
|
28
|
-
|
|
29
|
-
- **Asynchronous Dictionary Loading:**
|
|
30
|
-
On the client side, `useIntlayerAsync` first returns the pre-rendered locale dictionary (just like `useIntlayer`) and then asynchronously fetches and merges any newly available remote dictionaries.
|
|
31
|
-
- **Progress State Management:**
|
|
32
|
-
The hook also provides an `isLoading` state, indicating when a remote dictionary is being fetched. This allows developers to display loading indicators or skeleton states for a smoother user experience.
|
|
33
|
-
|
|
34
|
-
## Environment Setup
|
|
35
|
-
|
|
36
|
-
Intlayer provides a headless Content Source Management (CSM) system that empowers non-developers to manage and update application content seamlessly. By using Intlayer’s intuitive dashboard, your team can edit localised text, images, and other resources without directly modifying code. This streamlines the content management process, fosters collaboration, and ensures that updates can be made quickly and easily.
|
|
37
|
-
|
|
38
|
-
To get started with Intlayer, you will first need to register and obtain an access token in the [dashboard](https://intlayer.org/dashboard). Once you have your credentials, add them to your configuration file as shown below:
|
|
39
|
-
|
|
40
|
-
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
41
|
-
import type { IntlayerConfig } from "intlayer";
|
|
42
|
-
|
|
43
|
-
export default {
|
|
44
|
-
// ...
|
|
45
|
-
editor: {
|
|
46
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
47
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
48
|
-
},
|
|
49
|
-
} satisfies IntlayerConfig;
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
53
|
-
import { type IntlayerConfig } from "intlayer";
|
|
54
|
-
|
|
55
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
56
|
-
const config = {
|
|
57
|
-
// ...
|
|
58
|
-
editor: {
|
|
59
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
60
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export default config;
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
68
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
69
|
-
const config = {
|
|
70
|
-
// ...
|
|
71
|
-
editor: {
|
|
72
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
73
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
module.exports = config;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
After configuring your credentials, you can push a new locale dictionary to Intlayer by running:
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
npx intlayer dictionary push -d my-first-dictionary-key
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
This command uploads your initial content dictionaries, making them available for asynchronous fetching and editing through the Intlayer platform.
|
|
87
|
-
|
|
88
|
-
## Importing `useIntlayerAsync` in Next.js
|
|
89
|
-
|
|
90
|
-
Since `useIntlayerAsync` is intended for **client-side** components, you’ll import it from the same client entry point as `useIntlayer`:
|
|
91
|
-
|
|
92
|
-
```tsx codeFormat="typescript"
|
|
93
|
-
"use client";
|
|
94
|
-
|
|
95
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
```javascript codeFormat="esm"
|
|
99
|
-
"use client";
|
|
100
|
-
|
|
101
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
```javascript codeFormat="commonjs"
|
|
105
|
-
"use client";
|
|
106
|
-
|
|
107
|
-
const { useIntlayerAsync } = require("next-intlayer");
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Make sure that the importing file is annotated with `"use client"` at the top, if you’re using Next.js App Router with server and client components separated.
|
|
111
|
-
|
|
112
|
-
## Parameters
|
|
113
|
-
|
|
114
|
-
1. **`key`**:
|
|
115
|
-
**Type**: `DictionaryKeys`
|
|
116
|
-
The dictionary key used to identify the localised content block. This key should be defined in your content declaration files.
|
|
117
|
-
|
|
118
|
-
2. **`locale`** (optional):
|
|
119
|
-
**Type**: `Locales`
|
|
120
|
-
The specific locale you want to target. If omitted, the hook uses the locale from the client context.
|
|
121
|
-
|
|
122
|
-
3. **`isRenderEditor`** (optional, defaults to `true`):
|
|
123
|
-
**Type**: `boolean`
|
|
124
|
-
Determines whether the content should be ready for rendering with the Intlayer editor overlay. If set to `false`, the returned dictionary data will exclude editor-specific features.
|
|
125
|
-
|
|
126
|
-
## Return Value
|
|
127
|
-
|
|
128
|
-
The hook returns a dictionary object containing localised content keyed by `key` and `locale`. It also includes an `isLoading` boolean indicating whether a remote dictionary is currently being fetched.
|
|
129
|
-
|
|
130
|
-
## Example Usage in Next.js
|
|
131
|
-
|
|
132
|
-
### Client-Side Component Example
|
|
133
|
-
|
|
134
|
-
```tsx fileName="src/components/AsyncClientComponentExample.tsx" codeFormat="typescript"
|
|
135
|
-
"use client";
|
|
136
|
-
|
|
137
|
-
import { useEffect, type FC } from "react";
|
|
138
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
139
|
-
|
|
140
|
-
export const AsyncClientComponentExample: FC = () => {
|
|
141
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
142
|
-
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
if (isLoading) {
|
|
145
|
-
console.log("Content is loading...");
|
|
146
|
-
}
|
|
147
|
-
}, [isLoading]);
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<div>
|
|
151
|
-
<h1>{title.value}</h1>
|
|
152
|
-
<p>{description.value}</p>
|
|
153
|
-
</div>
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
```jsx fileName="src/components/AsyncClientComponentExample.mjx" codeFormat="esm"
|
|
159
|
-
"use client";
|
|
160
|
-
|
|
161
|
-
import { useEffect } from "react";
|
|
162
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
163
|
-
|
|
164
|
-
const AsyncClientComponentExample = () => {
|
|
165
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
166
|
-
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
if (isLoading) {
|
|
169
|
-
console.log("Content is loading...");
|
|
170
|
-
}
|
|
171
|
-
}, [isLoading]);
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
<div>
|
|
175
|
-
<h1>{title.value}</h1>
|
|
176
|
-
<p>{description.value}</p>
|
|
177
|
-
</div>
|
|
178
|
-
);
|
|
179
|
-
};
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
```jsx fileName="src/components/AsyncClientComponentExample.csx" codeFormat="commonjs"
|
|
183
|
-
"use client";
|
|
184
|
-
|
|
185
|
-
const { useEffect } = require("react");
|
|
186
|
-
const { useIntlayerAsync } = require("next-intlayer");
|
|
187
|
-
|
|
188
|
-
const AsyncClientComponentExample = () => {
|
|
189
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
190
|
-
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
if (isLoading) {
|
|
193
|
-
console.log("Content is loading...");
|
|
194
|
-
}
|
|
195
|
-
}, [isLoading]);
|
|
196
|
-
|
|
197
|
-
return (
|
|
198
|
-
<div>
|
|
199
|
-
<h1>{title.value}</h1>
|
|
200
|
-
<p>{description.value}</p>
|
|
201
|
-
</div>
|
|
202
|
-
);
|
|
203
|
-
};
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
**Key Points:**
|
|
207
|
-
|
|
208
|
-
- On initial render, `title` and `description` come from the pre-rendered locale dictionary.
|
|
209
|
-
- While `isLoading` is `true`, a remote request is made in the background to fetch an updated dictionary.
|
|
210
|
-
- Once the fetch completes, `title` and `description` are updated with the newest content, and `isLoading` returns to `false`.
|
|
211
|
-
|
|
212
|
-
## Handling Attribute Localisation
|
|
213
|
-
|
|
214
|
-
As with `useIntlayer`, you can retrieve localised attribute values for various HTML properties (e.g., `alt`, `title`, `aria-label`):
|
|
215
|
-
|
|
216
|
-
```tsx
|
|
217
|
-
<img src={title.image.src.value} alt={title.image.alt.value} />
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
## Dictionary Files
|
|
221
|
-
|
|
222
|
-
All content keys must be defined in your content declaration files for type safety and to prevent runtime errors. These files enable TypeScript validation, ensuring you always reference existing keys and locales.
|
|
223
|
-
|
|
224
|
-
Instructions for setting up content declaration files are available [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/dictionary/get_started.md).
|
|
225
|
-
|
|
226
|
-
## Further Information
|
|
227
|
-
|
|
228
|
-
- **Intlayer Visual Editor:**
|
|
229
|
-
Integrate with the Intlayer visual editor for managing and editing content directly from the UI. More details [here](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_visual_editor.md).
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
**In summary**, `useIntlayerAsync` is a powerful client-side hook designed to enhance the user experience and maintain content freshness by combining pre-rendered dictionaries with asynchronous dictionary updates. By leveraging `isLoading` and TypeScript-based content declarations, you can seamlessly integrate dynamic, localised content into your Next.js applications.
|
|
234
|
-
|
|
235
|
-
## Doc History
|
|
236
|
-
|
|
237
|
-
- 5.5.10 - 2025-06-29: Init history
|