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
Copy file name to clipboardExpand all lines: beta/src/content/apis/react/Fragment.md
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
-
title: Fragment (<>...</>)
2
+
title: Fragmento (<>...</>)
3
3
---
4
4
5
5
<Intro>
6
6
7
-
The `Fragment` component, which is often used via the `<>...</>` syntax, lets you render multiple elements in place of one, without wrapping them in any other container element.
7
+
El componente `Fragment`, que es se suele utilizar a través de la sintaxis `<>...</>`, te permite renderizar múltiples elementos en lugar de uno, sin tener que envolverlos dentro de otro elemento contenedor.
8
8
9
9
```js
10
10
<>
@@ -19,11 +19,11 @@ The `Fragment` component, which is often used via the `<>...</>` syntax, lets yo
19
19
20
20
---
21
21
22
-
## Usage {/*usage*/}
22
+
## Uso {/*usage*/}
23
23
24
-
### Returning multiple elements {/*returning-multiple-elements*/}
24
+
### Retornar múltiples elementos {/*returning-multiple-elements*/}
25
25
26
-
Use`Fragment`, or the equivalent `<>...</>` syntax, to group multiple elements together. You can use it to put multiple elements in any place where a single element can go. For example, a component can only return one element, but by using a Fragment you can group multiple elements together and then return them as a group:
26
+
Usa`Fragment`, o la sintaxis equivalente `<>...</>`, para agrupar múltiples elementos. Puedes usarlo para poner múltiples elementos en cualquier lugar donde un solo elemento puede ir. Por ejemplo, un componente solo puede retornar un elemento, pero usando un Fragmento puedes agrupar múltiples elementos y retornarlos como un grupo:
27
27
28
28
```js {3,6}
29
29
functionPost() {
@@ -36,7 +36,7 @@ function Post() {
36
36
}
37
37
```
38
38
39
-
Fragments are useful because grouping elements with a Fragment has no effect on layout or styles, unlike if you wrapped the elements in some other container such as a DOM element. If you inspect this example with the browser tools, you'll see that all `<h1>`and`<p>`DOM nodes appear as siblings without wrappers around them:
39
+
Los Fragmentos son útiles porque la agrupación de elementos con un Fragmento no tiene efecto en el diseño o los estilos, al contrario de cómo sería si envolvieras los elementos dentro de cualquier otro contenedor tal como un elemento del DOM. Si inspeccionas este ejemplo con las herramientas del navegador, verás que todos los nodos del DOM `<h1>`y`<p>`aparecen como hermanos sin envoltorios alrededor de ellos:
40
40
41
41
<Sandpack>
42
42
@@ -74,9 +74,9 @@ function PostBody({ body }) {
74
74
75
75
</Sandpack>
76
76
77
-
<DeepDivetitle="How to write a Fragment without the special syntax?">
77
+
<DeepDivetitle="¿Como escribir un fragmento sin la sintaxis especial?">
78
78
79
-
The example above is equivalent to importing`Fragment`from React:
79
+
El ejemplo anterior es equivalente a importar`Fragment`de React:
80
80
81
81
```js {1,5,8}
82
82
import { Fragment } from'react';
@@ -91,15 +91,15 @@ function Post() {
91
91
}
92
92
```
93
93
94
-
Usually you won't need this unless you need to [pass a`key`to your`Fragment`.](#rendering-a-list-of-fragments)
94
+
Usualmente no necesitarás esto a menos que necesites [pasar una`key`a tu`Fragment`.](#rendering-a-list-of-fragments)
95
95
96
96
</DeepDive>
97
97
98
98
---
99
99
100
-
### Assigning multiple elements to a variable {/*assigning-multiple-elements-to-a-variable*/}
100
+
### Asignar múltiples elementos a una variable {/*assigning-multiple-elements-to-a-variable*/}
101
101
102
-
Like any other element, you can assign Fragment elements to variables, pass them as props, and so on:
102
+
Como cualquier otro elemento, puedes asignar Fragmentos a variables, pasarlos como props, y así sucesivamente:
103
103
104
104
```js
105
105
functionCloseDialog() {
@@ -119,9 +119,9 @@ function CloseDialog() {
119
119
120
120
---
121
121
122
-
### Grouping elements with text {/*grouping-elements-with-text*/}
122
+
### Agrupar elementos con texto {/*grouping-elements-with-text*/}
123
123
124
-
You can use `Fragment`to group text together with components:
124
+
Puedes usar `Fragment`para agrupar texto con componentes:
125
125
126
126
```js
127
127
functionDateRangePicker({ start, end }) {
@@ -138,9 +138,9 @@ function DateRangePicker({ start, end }) {
138
138
139
139
---
140
140
141
-
### Rendering a list of Fragments {/*rendering-a-list-of-fragments*/}
141
+
### Renderizar una lista de fragmentos {/*rendering-a-list-of-fragments*/}
142
142
143
-
Here's a situation where you need to write `Fragment`explicitly instead of using the `<></>` syntax. When you [render multiple elements in a loop](/learn/rendering-lists), you need to assign a `key`to each element. If the elements within the loop are Fragments, you need to use the normal JSX element syntax in order to provide the`key` attribute:
143
+
Esta es una situación donde necesitas escribir `Fragment`explicitamente en lugar de usar la sintaxis `<></>`. Cuando [renderizas múltiples elementos dentro de un bucle](/learn/rendering-lists), necesitas asignar una `key`a cada elemento. Si los elementos dentro del bucle son Fragmentos, necesitar usar la sintaxis habitual de un elemento JSX con el fin de proveer el atributo`key`:
144
144
145
145
```js {3,6}
146
146
functionBlog() {
@@ -153,7 +153,7 @@ function Blog() {
153
153
}
154
154
```
155
155
156
-
You can inspect the DOM to verify that there are no wrapper elements around the Fragment children:
156
+
Puedes inspeccionar el DOM para verificar que no hay ningun envoltorio alrededor del Fragmento hijo:
157
157
158
158
<Sandpack>
159
159
@@ -191,20 +191,20 @@ function PostBody({ body }) {
191
191
192
192
---
193
193
194
-
## Reference {/*reference*/}
194
+
## Referencia {/*reference*/}
195
195
196
196
### `Fragment` {/*fragment*/}
197
197
198
-
Wrap elements in `<Fragment>`to group them together in situations where you need a single element. Grouping elements in`Fragment`has no effect on the resulting DOM; it is the same as if the elements were not grouped. The empty JSX tag`<></>`is shorthand for `<Fragment></Fragment>`in most cases.
198
+
Envuelve elementos en un `<Fragment>`para agruparlos en situaciones donde necesites un solo elemento. Agrupar elementos en`Fragment` no tiene efecto en el DOM resultante; ya que quedará igual que si los elementos no estuvieran agrupados. La etiqueta JSX vacía`<></>`es la abreviatura de `<Fragment></Fragment>`en la mayoría de los casos.
199
199
200
200
#### Props {/*fragment-props*/}
201
201
202
-
- **optional** `key`: Fragments declared with the explicit `<Fragment>`syntax may have [keys.](https://beta.reactjs.org/learn/rendering-lists#keeping-list-items-in-order-with-key)
202
+
- **Opcional** `key`: Los Fragmentos declarados con la sintaxis explícita `<Fragment>`pueden tener [llaves.](https://beta.reactjs.org/learn/rendering-lists#keeping-list-items-in-order-with-key)
203
203
204
-
#### Caveats {/*caveats*/}
204
+
#### Advertencias {/*caveats*/}
205
205
206
-
- If you want to pass `key`to a Fragment, you can't use the `<>...</>` syntax. You have to explicitly import `Fragment`from`'react'`and render`<Fragment key={yourKey}>...</Fragment>`.
206
+
- Si quisieras pasarle una `key`a un Fragmento, no podrias usar la sintaxis `<>...</>`. Tendrias que importar explícitamente `Fragment`desde`'react'`y renderizar`<Fragment key={yourKey}>...</Fragment>`.
207
207
208
-
- React does not [reset state](/learn/preserving-and-resetting-state) when you go from rendering `<><Child /></>`to `[<Child />]`or back, or when you go from rendering `<><Child /></>`to `<Child />`and back. This only works a single level deep: for example, going from `<><><Child /></></>`to `<Child />`resets the state. See the precise semantics [here.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
208
+
- React no [restablece el estado](/learn/preserving-and-resetting-state) cuando renderizas desde un `<><Child /></>`a un `[<Child />]`y viceversa, o cuando renderizas desde un `<><Child /></>`a un `<Child />`y viceversa. Ten en cuenta de que esto sólo funciona a un nivel de profundidad: por ejemplo, ir desde un `<><><Child /></></>`a un `<Child />`restablece el estado. Échale un ojo a la sintaxis en detalle [aquí.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
0 commit comments