Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate fragment (beta docs) #564

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions beta/src/content/apis/react/Fragment.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Fragment (<>...</>)
title: Fragmento (<>...</>)
---

<Intro>

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.
El componente `Fragment`, que es usualmente usado atraves de la sintaxis `<>...</>`, te permite renderizar múltiples elementos en lugar de uno, sin tener que envolverlos dentro de otro elemento contenedor.
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

```js
<>
Expand All @@ -19,11 +19,11 @@ The `Fragment` component, which is often used via the `<>...</>` syntax, lets yo

---

## Usage {/*usage*/}
## Uso {/*usage*/}

### Returning multiple elements {/*returning-multiple-elements*/}
### Retornando múltiples elementos {/*returning-multiple-elements*/}
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

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:
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:

```js {3,6}
function Post() {
Expand All @@ -36,7 +36,7 @@ function Post() {
}
```

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:
Los Fragmentos son útiles por que al agrupar varios elementos con un Fragmento no tiene efecto en el diseño o los estilos, a diferencia de si tu envolviste los elementos dentro de cualquier otro contenedor tal como un elemento del DOM. Si tu 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:
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

<Sandpack>

Expand Down Expand Up @@ -74,9 +74,9 @@ function PostBody({ body }) {

</Sandpack>

<DeepDive title="How to write a Fragment without the special syntax?">
<DeepDive title="¿Como escribir un fragmento sin la sintaxis especial?">

The example above is equivalent to importing `Fragment` from React:
El ejemplo anterior es equivalente a importar `Fragment` de React:

```js {1,5,8}
import { Fragment } from 'react';
Expand All @@ -91,15 +91,15 @@ function Post() {
}
```

Usually you won't need this unless you need to [pass a `key` to your `Fragment`.](#rendering-a-list-of-fragments)
Usualmente no necesitarás esto a menos que necesites [pasar una `key` a tu `Fragment`.](#rendering-a-list-of-fragments)

</DeepDive>

---

### Assigning multiple elements to a variable {/*assigning-multiple-elements-to-a-variable*/}
### Asignando múltiples elementos a una variable {/*assigning-multiple-elements-to-a-variable*/}
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

Like any other element, you can assign Fragment elements to variables, pass them as props, and so on:
Como cualquier otro elemento, puedes asignar Fragmentos a variables, pasarlos como props, y así sucesivamente:

```js
function CloseDialog() {
Expand All @@ -119,9 +119,9 @@ function CloseDialog() {

---

### Grouping elements with text {/*grouping-elements-with-text*/}
### Agrupando elementos con texto {/*grouping-elements-with-text*/}
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

You can use `Fragment` to group text together with components:
Puedes usar `Fragment` para agrupar texto con componentes:

```js
function DateRangePicker({ start, end }) {
Expand All @@ -138,9 +138,9 @@ function DateRangePicker({ start, end }) {

---

### Rendering a list of Fragments {/*rendering-a-list-of-fragments*/}
### Renderizando una lista de fragmentos {/*rendering-a-list-of-fragments*/}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Renderizando una lista de fragmentos {/*rendering-a-list-of-fragments*/}
### Renderizar una lista de fragmentos {/*rendering-a-list-of-fragments*/}

La traducción literal del gerundio en los títulos es desaconsejada en la guía de estilos, es recomendado utilizar un infinitivo o un sustantivo (Renderizando->Renderizado de || Renderización de || Renderizar).


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:
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 normal de un elemnto JSX con el fin de proveer el atributo `key`:
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

```js {3,6}
function Blog() {
Expand All @@ -153,7 +153,7 @@ function Blog() {
}
```

You can inspect the DOM to verify that there are no wrapper elements around the Fragment children:
Puedes inspeccionar el DOM para verificar que no hay ningun envoltorio alrededor del Fragmento hijo:

<Sandpack>

Expand Down Expand Up @@ -191,20 +191,20 @@ function PostBody({ body }) {

---

## Reference {/*reference*/}
## Referencia {/*reference*/}

### `Fragment` {/*fragment*/}

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.
Envolver elementos en un `<Fragment>` para agruparlos en situaciones donde necesitar un solo elemento. Agrupando elementos en `Fragment` no tiene efecto en el resultante del DOM; es lo mismo como si los elementos no estaban agrupados. La etiqueta JSX vacia `<></>` es la abreviatura de `<Fragment></Fragment>` en la mayoría de los casos.
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

#### Props {/*fragment-props*/}

- **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)
- **Opcional** `key`: Fragmentos declarados con la sintaxis explicita `<Fragment>` pueden tener [llaves.](https://beta.reactjs.org/learn/rendering-lists#keeping-list-items-in-order-with-key)
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

#### Caveats {/*caveats*/}
#### Advertencias {/*caveats*/}

- 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>`.
- Si quieres pasarle una `key` a un Fragmento, No puedes usar esta sintaxis `<>...</>`. Tienes que importar explicitamente `Fragment` desde `'react'` y renderizar `<Fragment key={yourKey}>...</Fragment>`.
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved

- 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)
- React no [restablece el estado](/learn/preserving-and-resetting-state) cuando vas desde renderizar `<><Child /></>` a `[<Child />]` o atrás, o cuando vas desde renderizar `<><Child /></>` a`<Child />` y atrás. Esto solo funciona a un nivel de profundidad: por ejemplo, yendo desde `<><><Child /></></>` a `<Child />` restablece el estado. Mira la sintaxis precisa [aquí.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
Vicenciomf1 marked this conversation as resolved.
Show resolved Hide resolved