Skip to content

Commit 0227fa3

Browse files
Translate createElement page (#577)
* translate createElement page * Apply suggestions from code review Co-authored-by: Rainer Martínez Fraga <rmartinezfraga@yandex.com>
1 parent c9bc0b5 commit 0227fa3

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

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

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

55
<Intro>
66

7-
`createElement` lets you create a React element. It serves as an alternative to writing [JSX.](/learn/writing-markup-with-jsx)
7+
`createElement` te permite crear un elemento React. Sirve como alternativa a escribir [JSX.](/learn/writing-markup-with-jsx)
88

99
```js
1010
const element = createElement(type, props, ...children)
@@ -16,13 +16,13 @@ const element = createElement(type, props, ...children)
1616

1717
---
1818

19-
## Usage {/*usage*/}
19+
## Uso {/*usage*/}
2020

21-
### Creating an element without JSX {/*creating-an-element-without-jsx*/}
21+
### Crear un elemento sin JSX {/*creating-an-element-without-jsx*/}
2222

23-
If you don't like [JSX](/learn/writing-markup-with-jsx) or can't use it in your project, you can use `createElement` as an alternative.
23+
Si no te gusta [JSX](/learn/writing-markup-with-jsx) o no puedes usarlo en tu proyecto, puedes usar `createElement` como alternativa.
2424

25-
To create an element without JSX, call `createElement` with some <CodeStep step={1}>type</CodeStep>, <CodeStep step={2}>props</CodeStep>, and <CodeStep step={3}>children</CodeStep>:
25+
Para crear un elemento sin JSX, llamas a `createElement` con <CodeStep step={1}>type</CodeStep>, <CodeStep step={2}>props</CodeStep> y <CodeStep step={3}>children</CodeStep>:
2626

2727
```js [[1, 5, "'h1'"], [2, 6, "{ className: 'greeting' }"], [3, 7, "'Hello ',"], [3, 8, "createElement('i', null, name),"], [3, 9, "'. Welcome!'"]]
2828
import { createElement } from 'react';
@@ -38,7 +38,7 @@ function Greeting({ name }) {
3838
}
3939
```
4040

41-
The <CodeStep step={3}>children</CodeStep> are optional, and you can pass as many as you need (the example above has three children). This code will display a `<h1>` header with a greeting. For comparison, here is the same example rewritten with JSX:
41+
Los <CodeStep step={3}>children</CodeStep> son opcionales, y puedes pasar tantos como necesites (el ejemplo anterior tiene tres hijos). Este código mostrará un encabezado `<h1>` con un saludo. A modo de comparación, aquí está el mismo ejemplo reescrito con JSX:
4242

4343
```js [[1, 3, "h1"], [2, 3, "className=\\"greeting\\""], [3, 4, "Hello <i>{name}</i>. Welcome!"], [1, 5, "h1"]]
4444
function Greeting({ name }) {
@@ -50,23 +50,23 @@ function Greeting({ name }) {
5050
}
5151
```
5252

53-
To render your own React component, pass a function like `Greeting` as the <CodeStep step={1}>type</CodeStep> instead of a string like `'h1'`:
53+
Para renderizar tu propio componente de React, pasas una función como `Greeting` como el <CodeStep step={1}>type</CodeStep> en lugar de un string como `'h1'`:
5454

5555
```js [[1, 2, "Greeting"], [2, 2, "{ name: 'Taylor' }"]]
5656
export default function App() {
5757
return createElement(Greeting, { name: 'Taylor' });
5858
}
5959
```
6060

61-
With JSX, it would look like this:
61+
Con JSX, se vería así:
6262

6363
```js [[1, 2, "Greeting"], [2, 2, "name=\\"Taylor\\""]]
6464
export default function App() {
6565
return <Greeting name="Taylor" />;
6666
}
6767
```
6868

69-
Here is a complete example written with `createElement`:
69+
Aquí hay un ejemplo completo escrito con `createElement`:
7070

7171
<Sandpack>
7272

@@ -100,7 +100,7 @@ export default function App() {
100100

101101
</Sandpack>
102102

103-
And here is the same example written using JSX:
103+
Y aquí está el mismo ejemplo usando JSX:
104104

105105
<Sandpack>
106106

@@ -127,11 +127,11 @@ export default function App() {
127127

128128
</Sandpack>
129129

130-
Both coding styles are fine, so you can use whichever one you prefer for your project. The main benefit of using JSX compared to `createElement` is that it's easy to see which closing tag corresponds to which opening tag.
130+
Ambos estilos de código están bien, por lo que puedes usar el que prefieras para tu proyecto. El principal beneficio de usar JSX en comparación con `createElement` es que es fácil ver qué etiqueta de cierre corresponde a qué etiqueta de apertura.
131131

132-
<DeepDive title="What is a React element, exactly?">
132+
<DeepDive title="Qué es exactamente un elemento React?">
133133

134-
An element is a lightweight description of a piece of the user interface. For example, both `<Greeting name="Taylor" />` and `createElement(Greeting, { name: 'Taylor' })` produce an object like this:
134+
Un elemento es una descripción ligera de una pieza de la interfaz de usuario. Por ejemplo, ambos `<Greeting name="Taylor" />` y `createElement(Greeting, { name: 'Taylor' })` producen un objeto como este:
135135

136136
```js
137137
// Slightly simplified
@@ -145,21 +145,21 @@ An element is a lightweight description of a piece of the user interface. For ex
145145
}
146146
```
147147

148-
**Note that creating this object does not render the `Greeting` component or create any DOM elements.**
148+
**Ten en cuenta que crear este objeto no representa el componente `Greeting` o crear cualquier elemento del DOM.**
149149

150-
A React element is more like a description--an instruction for React to later render the `Greeting` component. By returning this object from your `App` component, you tell React what to do next.
150+
Un elemento React es más como una descripción — una instrucción para React para luego renderizar el componente `Greeting`. Al devolver este objeto en tu componente `App`, le dices a React qué hacer a continuación.
151151

152-
Creating elements is extremely cheap so you don't need to try to optimize or avoid it.
152+
Crear elementos es extremadamente barato, por lo que no necesita intentar optimizarlo o evitarlo.
153153

154154
</DeepDive>
155155

156156
---
157157

158-
## Reference {/*reference*/}
158+
## Referencia {/*reference*/}
159159

160160
### `createElement(type, props, ...children)` {/*createelement*/}
161161

162-
Call `createElement` to create a React element with the given `type`, `props`, and `children`.
162+
Llamar `createElement` para crear un elemento de React con `type`, `props`, y `children`.
163163

164164
```js
165165
import { createElement } from 'react';
@@ -173,31 +173,31 @@ function Greeting({ name }) {
173173
}
174174
```
175175

176-
[See more examples above.](#usage)
176+
[Ver más ejemplos arriba.](#usage)
177177

178-
#### Parameters {/*parameters*/}
178+
#### Parámetros {/*parameters*/}
179179

180-
* `type`: The `type` argument must be a valid React component type. For example, it could be a tag name string (such as `'div'` or `'span'`), or a React component (a function, a class, or a special component like [`Fragment`](/apis/react/Fragment)).
180+
* `type`: El argumento `type` debe ser un tipo de componente de React válido. Por ejemplo, podría ser un string con el nombre de una etiqueta (como `'div'` o `'span'`), o un componente de React (una función, una clase, o un componente especial como [`Fragment`](/apis/react/Fragment)).
181181

182-
* `props`: The `props` argument must either be an object or `null`. If you pass `null`, it will be treated the same as an empty object. React will create an element with props matching the `props` you have passed. Note that `ref` and `key` from your `props` object are special and will *not* be available as `element.props.ref` and `element.props.key` on the returned `element`. They will be available as `element.ref` and `element.key`.
182+
* `props`: El argumento `props` debe ser un objeto o `null`. Si tu le pasas `null`, será tratado igual que un objecto vacío. React creará un elemento con props que coincidan con las `props` que has pasado. Ten en cuenta que `ref` y `key` de tu objecto `props` son especiales y lo harán *no* estar disponible como `element.props.ref` y `element.props.key` en el `element` devuelto. Estarán disponibles como `element.ref` y `element.key`.
183183

184-
* **optional** `...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [portals](/apis/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
184+
* **opcional** `...children`: Cero o más nodos. Pueden ser cualquier nodo de React, incluidos Elementos de React, strings, números, [portales](/apis/react-dom/createPortal), nodos vacíos (`null`, `undefined`, `true`, y `false`), y arrays con nodos de React.
185185

186-
#### Returns {/*returns*/}
186+
#### Devuelve {/*returns*/}
187187

188-
`createElement` returns a React element object with a few properties:
188+
`createElement` devuelve un objecto React element con algunas propiedades:
189189

190-
* `type`: The `type` you have passed.
191-
* `props`: The `props` you have passed except for `ref` and `key`. If the `type` is a component with legacy `type.defaultProps`, then any missing or undefined `props` will get the values from `type.defaultProps`.
192-
* `ref`: The `ref` you have passed. If missing, `null`.
193-
* `key`: The `key` you have passed, coerced to a string. If missing, `null`.
190+
* `type`: El `type` que pasaste.
191+
* `props`: Los `props` que pasaste excepto `ref` y `key`. Si el `type` es un componente con `type.defaultProps` heredado, entonces cualquier `props` que falte o `props` indefinidas obtendrá los valores de `type.defaultProps`.
192+
* `ref`: La `ref` que pasaste. Si no la pasaste es, `null`.
193+
* `key`: La `key` que pasaste, forzada a ser string. Si no la pasaste es, `null`.
194194

195-
Usually, you'll return the element from your component or make it a child of another element. Although you may read the element's properties, it's best to treat every element as opaque after it's created, and only render it.
195+
Por lo general, devolverá el elemento de tu componente o lo convertirá en hijo de otro elemento. Aunque puedes leer las propiedades del elemento, es mejor tratar cada elemento como opaco después de su creación, y solo renderizarlo.
196196

197-
#### Caveats {/*caveats*/}
197+
#### Advertencias {/*caveats*/}
198198

199-
* You must **treat React elements and their props as [immutable](https://en.wikipedia.org/wiki/Immutable_object)** and never change their contents after creation. In development, React will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) the returned element and its `props` property shallowly to enforce this.
199+
* Debes **tratar los elementos React y sus props como [inmutables](https://es.wikipedia.org/wiki/Objeto_inmutable)** y nunca cambiar sus contenidos después de creados. En desarrollo, React [congelaría](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) superficialmente el elemento devuelto y sus `props` para hacer cumplir esto.
200200

201-
* When you use JSX, **you must start a tag with a capital letter to render your own custom component.** In other words, `<Something />` is equivalent to `createElement(Something)`, but `<something />` (lowercase) is equivalent to `createElement('something')` (note it's a string, so it will be treated as a built-in HTML tag).
201+
* Cuando usas JSX, **debes comenzar una etiqueta con una letra mayúscula para renderizar tu propio componente personalizado.** En otras palabras, `<Something />` es equivalente a `createElement(Something)`, pero `<something />` (minúscula) es equivalente a `createElement('something')` (ten encuenta que es un string, por lo que se tratará como una etiqueta de HTML normal).
202202

203-
* You should only **pass children as multiple arguments to `createElement` if they are all statically known,** like `createElement('h1', {}, child1, child2, child3)`. If your children are dynamic, pass the entire array as the third argument: `createElement('ul', {}, listItems)`. This ensures that React will [warn you about missing `key`s](/learn/rendering-lists#keeping-list-items-in-order-with-key) for any dynamic lists. For static lists this is not necessary because they never reorder.
203+
* Solo deberías **pasar children como múltiples argumentos para `createElement` si todos son estáticamente conocidos,** como `createElement('h1', {}, child1, child2, child3)`. Si tus children son dinámicos, pasa todo el arreglo como tercer argumento: `createElement('ul', {}, listItems)`. Esto asegura que React [advertirá sobre la falta de `key`s](/learn/rendering-lists#keeping-list-items-in-order-with-key) para cualquier lista dinámica. Para las listas estáticas, esto no es necesario porque nunca se reordenan.

0 commit comments

Comments
 (0)