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
@@ -45,11 +46,11 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at
45
46
</>
46
47
```
47
48
48
-
**Let's walk through an example to see when this is useful.**
49
+
**Veamos un ejemplo para ver cuándo es útil.**
49
50
50
-
[HTML accessibility attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) like [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) let you specify that two tags are related to each other. For example, you can specify that a certain element (like an input) is described by another element (like a paragraph).
51
+
[Atributos de accesibilidad HTML](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) como [`aria-describedby`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby) te permiten especificar que dos etiquetas están relacionadas entre sí. Por ejemplo, puedes especificar que un determinado elemento (como una entrada de texto) sea descrito por otro elemento (como un párrafo).
51
52
52
-
In regular HTML, you would write it like this:
53
+
En HTML normal, lo escribirías así:
53
54
54
55
```html {5,8}
55
56
<label>
@@ -64,7 +65,7 @@ In regular HTML, you would write it like this:
64
65
</p>
65
66
```
66
67
67
-
However, hardcoding IDs like this is not a good practice in React. A component may be rendered more than once on the page--but IDs have to be unique! Instead of hardcoding an ID, you can generate a unique ID with`useId`:
68
+
Sin embargo, escribir IDs fijos como este no es una buena práctica en React. Un componente puede renderizarse más de una vez en la página, ¡pero los IDs tienen que ser únicos! En lugar de utilizar un ID fijo, puedes generar un ID único con`useId`:
68
69
69
70
```js {4,11,14}
70
71
import { useId } from'react';
@@ -88,7 +89,7 @@ function PasswordField() {
88
89
}
89
90
```
90
91
91
-
Now, even if`PasswordField`appears multiple times on the screen, the generated IDs won't clash.
92
+
Ahora, incluso si`PasswordField`aparece varias veces en la pantalla, no habrá conflicto entre los IDs generados.
92
93
93
94
<Sandpack>
94
95
@@ -131,31 +132,31 @@ input { margin: 5px; }
131
132
132
133
</Sandpack>
133
134
134
-
[Watch this video](https://www.youtube.com/watch?v=0dNzNcuEuOo) to see the difference in the user experience with assistive technologies.
135
+
[Mira este video](https://www.youtube.com/watch?v=0dNzNcuEuOo) para ver la diferencia en la experiencia de usuario con tecnologías de asistencia.
135
136
136
137
<Pitfall>
137
138
138
-
**`useId`requires an identical component tree on the server and the client** when you use [server rendering](/apis/react-dom/server). If the trees you render on the server and the client don't match exactly, the generated IDs won't match.
139
+
**`useId`requiere un árbol de componentes idéntico en el servidor y el cliente** cuando utilizas [renderizado en el servidor](/apis/react-dom/server). Si los árboles que se renderizan en el servidor y el cliente no coinciden exactamente, los IDs generados no coincidirán.
139
140
140
141
</Pitfall>
141
142
142
-
<DeepDive title="Why is useId better than an incrementing counter?">
143
+
<DeepDive title="¿Por qué useId es mejor que un contador incremental?">
143
144
144
-
You might be wondering why `useId`is better than incrementing a global variable like`nextId++`.
145
+
Puede que te preguntes por qué `useId`es mejor que incrementar una variable global como`nextId++`.
145
146
146
-
The primary benefit of`useId`is that React ensures that it works with [server rendering.](/apis/react-dom/server) During server rendering, your components generate HTML output. Later, on the client, [hydration](/apis/react-dom/client/hydrateRoot) attaches your event handlers to the generated HTML. For hydration to work, the client output must match the server HTML.
147
+
El principal beneficio de`useId`es que React se asegura de que funcione con el [renderizado en el servidor.](/apis/react-dom/server) Durante el renderizado en el servidos, tus componentes generan salida HTML. Más tarde, en el cliente, [la hidratación](/apis/react-dom/client/hydrateRoot) adjunta tus controladores de eventos al HTML generado. Para que la hidratación funcione, la salida del cliente debe coincidir con el HTML del servidor.
147
148
148
-
This is very difficult to guarantee with an incrementing counter because the order in which the client components are hydrated may not match the order in which the server HTML was emitted. By calling `useId`, you ensure that hydration will work, and the output will match between the server and the client.
149
+
Esto es muy difícil de garantizar con un contador incremental porque el orden en que se hidratan los componentes del cliente puede no coincidir con el orden en que se emitió el HTML del servidor. Al llamar a `useId`, te aseguras de que la hidratación funcionará y la salida coincidirá entre el servidor y el cliente.
149
150
150
-
Inside React, `useId`is generated from the "parent path" of the calling component. This is why, if the client and the server tree are the same, the "parent path" will match up regardless of rendering order.
151
+
Dentro de React, `useId`se genera a partir de la "ruta del padre" del componente llamado. Esta es la razón por la que, si el cliente y el árbol del servidor son iguales, la "ruta del padre" coincidirá independientemente del orden del renderizado.
151
152
152
153
</DeepDive>
153
154
154
155
---
155
156
156
-
### Generating IDs for several related elements {/*generating-ids-for-several-related-elements*/}
157
+
### Generar IDs para varios elementos relacionados {/*generating-ids-for-several-related-elements*/}
157
158
158
-
If you need to give IDs to multiple related elements, you can call`useId`to generate a shared prefix for them:
159
+
Si necesitas proporcionar IDs a varios elementos relacionados, puedes llamar a`useId`para generar un prefijo compartido para ellos:
159
160
160
161
<Sandpack>
161
162
@@ -182,13 +183,13 @@ input { margin: 5px; }
182
183
183
184
</Sandpack>
184
185
185
-
This lets you avoid calling `useId`for every single element that needs a unique ID.
186
+
Esto te permite evitar llamar a `useId`para cada elemento que necesite un ID único.
186
187
187
188
---
188
189
189
-
### Specifying a shared prefix for all generated IDs {/*specifying-a-shared-prefix-for-all-generated-ids*/}
190
+
### Especificación de un prefijo compartido para todos los IDs generados {/*specifying-a-shared-prefix-for-all-generated-ids*/}
190
191
191
-
If you render multiple independent React applications on a single page, you may pass `identifierPrefix`as an option to your [`createRoot`](/apis/react-dom/client/createRoot#parameters) or [`hydrateRoot`](/apis/react-dom/client/hydrateRoot) calls. This ensures that the IDs generated by the two different apps never clash because every identifier generated with `useId`will start with the distinct prefix you've specified.
192
+
Si renderizas varias aplicaciones de React independientes en una sola página, puedes pasar `identifierPrefix`como una opción para las llamadas [`createRoot`](/apis/react-dom/client/createRoot#parameters) o [`hydrateRoot`](/apis/react-dom/client/hydrateRoot). Esto garantiza que los IDs generados por las dos aplicaciones diferentes nunca entren en conflicto porque cada identificador generado con `useId`comenzará con el prefijo distinto que hayas especificado.
192
193
193
194
<Sandpack>
194
195
@@ -271,11 +272,11 @@ input { margin: 5px; }
271
272
272
273
---
273
274
274
-
## Reference {/*reference*/}
275
+
## Referencia {/*reference*/}
275
276
276
277
### `useId()` {/*useid*/}
277
278
278
-
Call `useId`at the top level of your component to generate a unique ID:
279
+
Llama a `useId`en el nivel superior de tu componente para generar un ID único:
279
280
280
281
```js
281
282
import { useId } from'react';
@@ -285,18 +286,18 @@ function PasswordField() {
285
286
// ...
286
287
```
287
288
288
-
[See more examples above.](#usage)
289
+
[Ve más ejemplos arriba.](#usage)
289
290
290
-
#### Parameters {/*parameters*/}
291
+
#### Parámetros {/*parameters*/}
291
292
292
-
`useId`does not take any parameters.
293
+
`useId`no toma ningún parámetro.
293
294
294
-
#### Returns {/*returns*/}
295
+
#### Retorna {/*returns*/}
295
296
296
-
`useId`returns a unique ID string associated with this particular`useId`call in this particular component.
297
+
`useId`devuelve una cadena de ID única asociada con esta llamada`useId`llamado en un componente particular.
297
298
298
-
#### Caveats {/*caveats*/}
299
+
#### Advertencias {/*caveats*/}
299
300
300
-
* `useId`is a Hook, so you can only call it **at the top level of your component** or your own Hooks. You can't call it inside loops or conditions. If you need that, extract a new component and move the state into it.
301
+
* `useId`es un Hook, así que solo puedes llamarlo **en el nivel superior de tu componente** o en tus propios hooks. No puedes llamarlo dentro de bucles o condiciones. Si necesitas hacerlo, extrae un nuevo componente y mueve allí el estado.
301
302
302
-
* `useId` **should not be used to generate keys** in a list. [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)
303
+
* `useId` **no debe usarse para generar keys** en una lista. [Las keys deben generarse a partir de tus datos.](/learn/rendering-lists#where-to-get-your-key)
0 commit comments