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: content/docs/fragments.md
+20-21Lines changed: 20 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,9 @@
1
1
---
2
2
id: fragments
3
-
title: Fragments
3
+
title: Fragmentos
4
4
permalink: docs/fragments.html
5
5
---
6
-
7
-
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.
6
+
Un patrón común en React es que un componente devuelva multiples elementos. Los Fragmentos te permiten agrupar una lista de hijos sin agregar nodos extra al DOM.
8
7
9
8
```js
10
9
render() {
@@ -18,11 +17,11 @@ render() {
18
17
}
19
18
```
20
19
21
-
There is also a new [short syntax](#short-syntax) for declaring them, but it isn't supported by all popular tools yet.
20
+
También hay una nueva [sintaxis corta](#sintaxis-corta) para declararlos, pero aún no es soportada por todas las herramientas populares.
22
21
23
-
## Motivation
22
+
## Motivación
24
23
25
-
A common pattern is for a component to return a list of children. Take this example React snippet:
24
+
Un patrón común es que un componente devuelva una lista de hijos. Toma este código de ejemplo en React:
26
25
27
26
```jsx
28
27
classTableextendsReact.Component {
@@ -38,7 +37,7 @@ class Table extends React.Component {
38
37
}
39
38
```
40
39
41
-
`<Columns />`would need to return multiple`<td>`elements in order for the rendered HTML to be valid. If a parent div was used inside the `render()`of`<Columns />`, then the resulting HTML will be invalid.
40
+
`<Columns />`tendría que devolver múltiples elementos`<td>`para que el código HTML renderizado sea válido. Si un div padre fue utilizado dentro del código `render()`de`<Columns />`, entonces el código HTML resultante será inválido.
42
41
43
42
```jsx
44
43
classColumnsextendsReact.Component {
@@ -53,7 +52,7 @@ class Columns extends React.Component {
53
52
}
54
53
```
55
54
56
-
results in a `<Table />`output of:
55
+
resulta en una salida de `<Table />`de:
57
56
58
57
```jsx
59
58
<table>
@@ -66,9 +65,9 @@ results in a `<Table />` output of:
66
65
</table>
67
66
```
68
67
69
-
Fragments solve this problem.
68
+
Los Fragmentos solucionan este problema.
70
69
71
-
## Usage
70
+
## Uso
72
71
73
72
```jsx{4,7}
74
73
class Columns extends React.Component {
@@ -83,7 +82,7 @@ class Columns extends React.Component {
83
82
}
84
83
```
85
84
86
-
which results in a correct `<Table />`output of:
85
+
que resulta en una salida correcta de `<Table />`de:
87
86
88
87
```jsx
89
88
<table>
@@ -94,9 +93,9 @@ which results in a correct `<Table />` output of:
94
93
</table>
95
94
```
96
95
97
-
### Short Syntax
96
+
### Sintaxis corta
98
97
99
-
There is a new, shorter syntax you can use for declaring fragments. It looks like empty tags:
98
+
Hay una sintaxis nueva, más corta que puedes usar para declarar fragmentos. Parecen etiquetas vacías:
100
99
101
100
```jsx{4,7}
102
101
class Columns extends React.Component {
@@ -111,20 +110,20 @@ class Columns extends React.Component {
111
110
}
112
111
```
113
112
114
-
You can use `<></>`the same way you'd use any other element except that it doesn't support keys or attributes.
113
+
Puedes utilizar `<></>`de la misma manera que usarías cualquier otro elemento, excepto que este no soporta llaves o atributos.
115
114
116
-
Note that**[many tools don't support it yet](/blog/2017/11/28/react-v16.2.0-fragment-support.html#support-for-fragment-syntax)** so you might want to explicitly write `<React.Fragment>`until the tooling catches up.
115
+
Considera que:**[muchas herramientas no lo soportan aún](/blog/2017/11/28/react-v16.2.0-fragment-support.html#support-for-fragment-syntax)**, por lo que podrías escribir explícitamente `<React.Fragment>`hasta que las herramientas se pongan al día.
117
116
118
-
### Keyed Fragments
117
+
### Fragmentos incrustados
119
118
120
-
Fragments declared with the explicit `<React.Fragment>`syntax may have keys. A use case for this is mapping a collection to an array of fragments -- for example, to create a description list:
119
+
Fragmentos declarados con la sintaxis explícita `<React.Fragment>`pueden tener llaves. Un caso de uso para esto es el mapeo de una colección a un arreglo de fragmentos -- por ejemplo, para crear una lista de descripción:
121
120
122
121
```jsx
123
122
functionGlossary(props) {
124
123
return (
125
124
<dl>
126
125
{props.items.map(item=> (
127
-
//Without the `key`, React will fire a key warning
126
+
//Sin el prop 'key', React disparará una advertencia de key
128
127
<React.Fragment key={item.id}>
129
128
<dt>{item.term}</dt>
130
129
<dd>{item.description}</dd>
@@ -135,8 +134,8 @@ function Glossary(props) {
135
134
}
136
135
```
137
136
138
-
`key`is the only attribute that can be passed to`Fragment`. In the future, we may add support for additional attributes, such as event handlers.
137
+
`key`es el único atributo que se puede pasar a`Fragment`. En el futuro, vamos a agregar soporte para atributos adicionales como manejadores de eventos.
139
138
140
-
### Live Demo
139
+
### Demostración en vivo
141
140
142
-
You can try out the new JSX fragment syntax with this[CodePen](https://codepen.io/reactjs/pen/VrEbjE?editors=1000).
141
+
Puedes probar la nueva sintaxis de fragmentos JSX con este[CodePen](https://codepen.io/reactjs/pen/VrEbjE?editors=1000).
0 commit comments