@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,257 +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
|
-
- Internationalisation
|
|
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 localised 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 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:
|
|
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 localised 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 localised 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
|
-
</div>
|
|
189
|
-
)}
|
|
190
|
-
</div>
|
|
191
|
-
);
|
|
192
|
-
};
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
```jsx fileName="src/components/ComponentExample.csx" codeFormat="commonjs"
|
|
196
|
-
const { useEffect } = require("react");
|
|
197
|
-
const { useIntlayerAsync } = require("react-intlayer");
|
|
198
|
-
|
|
199
|
-
const ComponentExample = () => {
|
|
200
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
201
|
-
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (isLoading) {
|
|
204
|
-
console.log("Content is loading...");
|
|
205
|
-
}
|
|
206
|
-
}, [isLoading]);
|
|
207
|
-
|
|
208
|
-
return (
|
|
209
|
-
<div>
|
|
210
|
-
{isLoading ? (
|
|
211
|
-
<div>
|
|
212
|
-
<h1>Loading…</h1>
|
|
213
|
-
<p>Please wait while content updates.</p>
|
|
214
|
-
</div>
|
|
215
|
-
) : (
|
|
216
|
-
<div>
|
|
217
|
-
<h1>{title.value}</h1>
|
|
218
|
-
<p>{description.value}</p>
|
|
219
|
-
</div>
|
|
220
|
-
)}
|
|
221
|
-
</div>
|
|
222
|
-
);
|
|
223
|
-
};
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
**Key Points:**
|
|
227
|
-
|
|
228
|
-
- On initial render, `title` and `description` come from the pre-fetched or statically embedded locale dictionary.
|
|
229
|
-
- While `isLoading` is `true`, a background request fetches an updated dictionary.
|
|
230
|
-
- Once the fetch completes, `title` and `description` are updated with the newest content, and `isLoading` returns to `false`.
|
|
231
|
-
|
|
232
|
-
## Handling Attribute Localisation
|
|
233
|
-
|
|
234
|
-
You can also retrieve localised attribute values for various HTML properties (e.g., `alt`, `title`, `aria-label`):
|
|
235
|
-
|
|
236
|
-
```jsx
|
|
237
|
-
<img src={title.image.src.value} alt={title.image.alt.value} />
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## Dictionary Files
|
|
241
|
-
|
|
242
|
-
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.
|
|
243
|
-
|
|
244
|
-
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).
|
|
245
|
-
|
|
246
|
-
## Further Information
|
|
247
|
-
|
|
248
|
-
- **Intlayer Visual Editor:**
|
|
249
|
-
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).
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
**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, localised content into your React applications.
|
|
254
|
-
|
|
255
|
-
## Doc History
|
|
256
|
-
|
|
257
|
-
- 5.5.10 - 2025-06-29: Init history
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
createdAt: 2024-08-11
|
|
3
|
-
updatedAt: 2025-06-29
|
|
4
|
-
title: Documentación del Hook useIntlayerAsync | next-intlayer
|
|
5
|
-
description: Vea cómo usar el hook useIntlayerAsync para el paquete next-intlayer
|
|
6
|
-
keywords:
|
|
7
|
-
- useIntlayerAsync
|
|
8
|
-
- diccionario
|
|
9
|
-
- clave
|
|
10
|
-
- Intlayer
|
|
11
|
-
- Internacionalización
|
|
12
|
-
- Documentación
|
|
13
|
-
- Next.js
|
|
14
|
-
- JavaScript
|
|
15
|
-
- React
|
|
16
|
-
slugs:
|
|
17
|
-
- doc
|
|
18
|
-
- packages
|
|
19
|
-
- next-intlayer
|
|
20
|
-
- useIntlayerAsync
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
# Integración con Next.js: Documentación del Hook `useIntlayerAsync`
|
|
24
|
-
|
|
25
|
-
El hook `useIntlayerAsync` extiende la funcionalidad de `useIntlayer` al no solo devolver diccionarios pre-renderizados, sino también al obtener actualizaciones de forma asíncrona, lo que lo hace ideal para aplicaciones que actualizan frecuentemente su contenido localizado después del renderizado inicial.
|
|
26
|
-
|
|
27
|
-
## Resumen
|
|
28
|
-
|
|
29
|
-
- **Carga asíncrona de diccionarios:**
|
|
30
|
-
En el lado del cliente, `useIntlayerAsync` primero devuelve el diccionario de localización pre-renderizado (igual que `useIntlayer`) y luego obtiene y fusiona de forma asíncrona cualquier diccionario remoto nuevo disponible.
|
|
31
|
-
- **Gestión del estado de progreso:**
|
|
32
|
-
El hook también proporciona un estado `isLoading`, que indica cuándo se está obteniendo un diccionario remoto. Esto permite a los desarrolladores mostrar indicadores de carga o estados esqueleto para una experiencia de usuario más fluida.
|
|
33
|
-
|
|
34
|
-
## Configuración del entorno
|
|
35
|
-
|
|
36
|
-
Intlayer proporciona un sistema de Gestión de Fuentes de Contenido (CSM) sin interfaz (headless) que permite a personas no desarrolladoras gestionar y actualizar el contenido de la aplicación de manera fluida. Usando el panel intuitivo de Intlayer, tu equipo puede editar textos localizados, imágenes y otros recursos sin modificar directamente el código. Esto agiliza el proceso de gestión de contenido, fomenta la colaboración y asegura que las actualizaciones se puedan realizar rápida y fácilmente.
|
|
37
|
-
|
|
38
|
-
Para comenzar con Intlayer, primero deberás registrarte y obtener un token de acceso en el [panel de control](https://intlayer.org/dashboard). Una vez que tengas tus credenciales, añádelas a tu archivo de configuración como se muestra a continuación:
|
|
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
|
-
// Configuración para Intlayer
|
|
57
|
-
const config = {
|
|
58
|
-
// ...
|
|
59
|
-
editor: {
|
|
60
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
61
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export default config;
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
69
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
70
|
-
// Configuración para Intlayer
|
|
71
|
-
const config = {
|
|
72
|
-
// ...
|
|
73
|
-
editor: {
|
|
74
|
-
clientId: process.env.INTLAYER_CLIENT_ID,
|
|
75
|
-
clientSecret: process.env.INTLAYER_CLIENT_SECRET,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
module.exports = config;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Después de configurar tus credenciales, puedes enviar un nuevo diccionario de localización a Intlayer ejecutando:
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
npx intlayer dictionary push -d my-first-dictionary-key
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Este comando sube tus diccionarios de contenido iniciales, haciéndolos disponibles para su obtención y edición asíncrona a través de la plataforma Intlayer.
|
|
89
|
-
|
|
90
|
-
## Importando `useIntlayerAsync` en Next.js
|
|
91
|
-
|
|
92
|
-
Dado que `useIntlayerAsync` está destinado para componentes **del lado del cliente**, lo importarás desde el mismo punto de entrada del cliente que `useIntlayer`:
|
|
93
|
-
|
|
94
|
-
```tsx codeFormat="typescript"
|
|
95
|
-
"use client";
|
|
96
|
-
|
|
97
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
```javascript codeFormat="esm"
|
|
101
|
-
"use client";
|
|
102
|
-
|
|
103
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
```javascript codeFormat="commonjs"
|
|
107
|
-
"use client";
|
|
108
|
-
|
|
109
|
-
const { useIntlayerAsync } = require("next-intlayer");
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Asegúrate de que el archivo que importa esté anotado con `"use client"` en la parte superior, si estás usando Next.js App Router con componentes de servidor y cliente separados.
|
|
113
|
-
|
|
114
|
-
## Parámetros
|
|
115
|
-
|
|
116
|
-
1. **`key`**:
|
|
117
|
-
**Tipo**: `DictionaryKeys`
|
|
118
|
-
La clave del diccionario usada para identificar el bloque de contenido localizado. Esta clave debe estar definida en tus archivos de declaración de contenido.
|
|
119
|
-
|
|
120
|
-
2. **`locale`** (opcional):
|
|
121
|
-
**Tipo**: `Locales`
|
|
122
|
-
La localización específica a la que deseas dirigirte. Si se omite, el hook usa la localización del contexto del cliente.
|
|
123
|
-
|
|
124
|
-
3. **`isRenderEditor`** (opcional, por defecto `true`):
|
|
125
|
-
**Tipo**: `boolean`
|
|
126
|
-
Determina si el contenido debe estar listo para renderizarse con la superposición del editor Intlayer. Si se establece en `false`, los datos del diccionario devueltos excluirán las características específicas del editor.
|
|
127
|
-
|
|
128
|
-
## Valor de Retorno
|
|
129
|
-
|
|
130
|
-
El hook devuelve un objeto diccionario que contiene contenido localizado identificado por `key` y `locale`. También incluye un booleano `isLoading` que indica si actualmente se está obteniendo un diccionario remoto.
|
|
131
|
-
|
|
132
|
-
## Ejemplo de Uso en Next.js
|
|
133
|
-
|
|
134
|
-
### Ejemplo de Componente del Lado del Cliente
|
|
135
|
-
|
|
136
|
-
```tsx fileName="src/components/AsyncClientComponentExample.tsx" codeFormat="typescript"
|
|
137
|
-
"use client";
|
|
138
|
-
|
|
139
|
-
import { useEffect, type FC } from "react";
|
|
140
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
141
|
-
|
|
142
|
-
export const AsyncClientComponentExample: FC = () => {
|
|
143
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
144
|
-
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
if (isLoading) {
|
|
147
|
-
console.log("El contenido se está cargando...");
|
|
148
|
-
}
|
|
149
|
-
}, [isLoading]);
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<div>
|
|
153
|
-
<h1>{title.value}</h1>
|
|
154
|
-
<p>{description.value}</p>
|
|
155
|
-
</div>
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
```jsx fileName="src/components/AsyncClientComponentExample.mjx" codeFormat="esm"
|
|
161
|
-
"use client";
|
|
162
|
-
|
|
163
|
-
import { useEffect } from "react";
|
|
164
|
-
import { useIntlayerAsync } from "next-intlayer";
|
|
165
|
-
|
|
166
|
-
const AsyncClientComponentExample = () => {
|
|
167
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
168
|
-
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
if (isLoading) {
|
|
171
|
-
console.log("El contenido se está cargando...");
|
|
172
|
-
}
|
|
173
|
-
}, [isLoading]);
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<div>
|
|
177
|
-
<h1>{title.value}</h1>
|
|
178
|
-
<p>{description.value}</p>
|
|
179
|
-
</div>
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
```jsx fileName="src/components/AsyncClientComponentExample.csx" codeFormat="commonjs"
|
|
185
|
-
"use client";
|
|
186
|
-
|
|
187
|
-
const { useEffect } = require("react");
|
|
188
|
-
const { useIntlayerAsync } = require("next-intlayer");
|
|
189
|
-
|
|
190
|
-
const AsyncClientComponentExample = () => {
|
|
191
|
-
const { title, description, isLoading } = useIntlayerAsync("async-component");
|
|
192
|
-
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
if (isLoading) {
|
|
195
|
-
console.log("El contenido se está cargando...");
|
|
196
|
-
}
|
|
197
|
-
}, [isLoading]);
|
|
198
|
-
|
|
199
|
-
return (
|
|
200
|
-
<div>
|
|
201
|
-
<h1>{title.value}</h1>
|
|
202
|
-
<p>{description.value}</p>
|
|
203
|
-
</div>
|
|
204
|
-
);
|
|
205
|
-
};
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
**Puntos clave:**
|
|
209
|
-
|
|
210
|
-
- En la renderización inicial, `title` y `description` provienen del diccionario de locales pre-renderizado.
|
|
211
|
-
|
|
212
|
-
- Mientras `isLoading` sea `true`, se realiza una solicitud remota en segundo plano para obtener un diccionario actualizado.
|
|
213
|
-
- Una vez que la obtención finaliza, `title` y `description` se actualizan con el contenido más reciente, y `isLoading` vuelve a `false`.
|
|
214
|
-
|
|
215
|
-
## Manejo de la Localización de Atributos
|
|
216
|
-
|
|
217
|
-
Al igual que con `useIntlayer`, puedes obtener valores localizados para atributos de HTML diversos (por ejemplo, `alt`, `title`, `aria-label`):
|
|
218
|
-
|
|
219
|
-
```tsx
|
|
220
|
-
<img src={title.image.src.value} alt={title.image.alt.value} />
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Archivos de Diccionario
|
|
224
|
-
|
|
225
|
-
Todas las claves de contenido deben estar definidas en tus archivos de declaración de contenido para garantizar la seguridad de tipos y evitar errores en tiempo de ejecución. Estos archivos permiten la validación con TypeScript, asegurando que siempre hagas referencia a claves y locales existentes.
|
|
226
|
-
|
|
227
|
-
Las instrucciones para configurar los archivos de declaración de contenido están disponibles [aquí](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/dictionary/get_started.md).
|
|
228
|
-
|
|
229
|
-
## Información adicional
|
|
230
|
-
|
|
231
|
-
- **Editor Visual de Intlayer:**
|
|
232
|
-
Integra con el editor visual de Intlayer para gestionar y editar contenido directamente desde la interfaz de usuario. Más detalles [aquí](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_visual_editor.md).
|
|
233
|
-
|
|
234
|
-
---
|
|
235
|
-
|
|
236
|
-
**En resumen**, `useIntlayerAsync` es un potente hook del lado del cliente diseñado para mejorar la experiencia del usuario y mantener la frescura del contenido al combinar diccionarios pre-renderizados con actualizaciones asíncronas de diccionarios. Aprovechando `isLoading` y las declaraciones de contenido basadas en TypeScript, puedes integrar de manera fluida contenido dinámico y localizado en tus aplicaciones Next.js.
|
|
237
|
-
|
|
238
|
-
## Historial de la documentación
|
|
239
|
-
|
|
240
|
-
- 5.5.10 - 2025-06-29: Historial inicial
|