Skip to content

Commit 1c75d35

Browse files
Isaias077carburo
andauthored
Translate useId (#575)
* Translation from English to Spanish * Apply suggestions from code review Co-authored-by: Rainer Martínez Fraga <rmartinezfraga@yandex.com>
1 parent 3cf8bcd commit 1c75d35

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

beta/src/content/apis/react/useId.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ title: useId
44

55
<Intro>
66

7-
`useId` is a React Hook for generating unique IDs that can be passed to accessibility attributes.
7+
`useId` es un Hook de React para generar IDs únicos que se pueden pasar a los atributos de accesibilidad.
8+
89

910
```js
1011
const id = useId()
@@ -16,17 +17,17 @@ const id = useId()
1617

1718
---
1819

19-
## Usage {/*usage*/}
20+
## Uso {/*usage*/}
2021

2122
<Pitfall>
2223

23-
**Do not call `useId` to generate keys in a list.** [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)
24+
**No utilices `useId` para generar keys en una lista.** [Las keys deben generarse a partir de tus datos.](/learn/rendering-lists#where-to-get-your-key)
2425

2526
</Pitfall>
2627

27-
### Generating unique IDs for accessibility attributes {/*generating-unique-ids-for-accessibility-attributes*/}
28+
### Generación de ID únicos para atributos de accesibilidad {/*generating-unique-ids-for-accessibility-attributes*/}
2829

29-
Call `useId` at the top level of your component to generate a unique ID:
30+
Llama a `useId` en el nivel superior de tu componente para generar un ID único:
3031

3132
```js [[1, 4, "passwordHintId"]]
3233
import { useId } from 'react';
@@ -36,7 +37,7 @@ function PasswordField() {
3637
// ...
3738
```
3839
39-
You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different attributes:
40+
A continuación, puedes pasar el <CodeStep step={1}>ID generado</CodeStep> a los diferentes atributos:
4041
4142
```js [[1, 2, "passwordHintId"], [1, 3, "passwordHintId"]]
4243
<>
@@ -45,11 +46,11 @@ You can then pass the <CodeStep step={1}>generated ID</CodeStep> to different at
4546
</>
4647
```
4748
48-
**Let's walk through an example to see when this is useful.**
49+
**Veamos un ejemplo para ver cuándo es útil.**
4950
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).
5152
52-
In regular HTML, you would write it like this:
53+
En HTML normal, lo escribirías así:
5354
5455
```html {5,8}
5556
<label>
@@ -64,7 +65,7 @@ In regular HTML, you would write it like this:
6465
</p>
6566
```
6667
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`:
6869
6970
```js {4,11,14}
7071
import { useId } from 'react';
@@ -88,7 +89,7 @@ function PasswordField() {
8889
}
8990
```
9091
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.
9293
9394
<Sandpack>
9495
@@ -131,31 +132,31 @@ input { margin: 5px; }
131132
132133
</Sandpack>
133134
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.
135136
136137
<Pitfall>
137138
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.
139140
140141
</Pitfall>
141142
142-
<DeepDive title="Why is useId better than an incrementing counter?">
143+
<DeepDive title="¿Por qué useId es mejor que un contador incremental?">
143144
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++`.
145146
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.
147148
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.
149150
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.
151152
152153
</DeepDive>
153154
154155
---
155156
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*/}
157158
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:
159160
160161
<Sandpack>
161162
@@ -182,13 +183,13 @@ input { margin: 5px; }
182183
183184
</Sandpack>
184185
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.
186187
187188
---
188189
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*/}
190191
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.
192193
193194
<Sandpack>
194195
@@ -271,11 +272,11 @@ input { margin: 5px; }
271272
272273
---
273274
274-
## Reference {/*reference*/}
275+
## Referencia {/*reference*/}
275276
276277
### `useId()` {/*useid*/}
277278
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:
279280
280281
```js
281282
import { useId } from 'react';
@@ -285,18 +286,18 @@ function PasswordField() {
285286
// ...
286287
```
287288
288-
[See more examples above.](#usage)
289+
[Ve más ejemplos arriba.](#usage)
289290
290-
#### Parameters {/*parameters*/}
291+
#### Parámetros {/*parameters*/}
291292
292-
`useId` does not take any parameters.
293+
`useId` no toma ningún parámetro.
293294
294-
#### Returns {/*returns*/}
295+
#### Retorna {/*returns*/}
295296
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.
297298
298-
#### Caveats {/*caveats*/}
299+
#### Advertencias {/*caveats*/}
299300
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.
301302
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

Comments
 (0)