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
@@ -16,13 +16,13 @@ const element = createElement(type, props, ...children)
16
16
17
17
---
18
18
19
-
## Usage {/*usage*/}
19
+
## Uso {/*usage*/}
20
20
21
-
### Creating an element without JSX {/*creating-an-element-without-jsx*/}
21
+
### Crear un elemento sin JSX {/*creating-an-element-without-jsx*/}
22
22
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.
24
24
25
-
To create an element without JSX, call `createElement`with some <CodeStepstep={1}>type</CodeStep>, <CodeStepstep={2}>props</CodeStep>, and <CodeStepstep={3}>children</CodeStep>:
25
+
Para crear un elemento sin JSX, llamas a `createElement`con <CodeStepstep={1}>type</CodeStep>, <CodeStepstep={2}>props</CodeStep> y <CodeStepstep={3}>children</CodeStep>:
The <CodeStepstep={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 <CodeStepstep={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:
To render your own React component, pass a function like`Greeting`as the <CodeStepstep={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 <CodeStepstep={1}>type</CodeStep> en lugar de un string como`'h1'`:
Here is a complete example written with`createElement`:
69
+
Aquí hay un ejemplo completo escrito con`createElement`:
70
70
71
71
<Sandpack>
72
72
@@ -100,7 +100,7 @@ export default function App() {
100
100
101
101
</Sandpack>
102
102
103
-
And here is the same example written using JSX:
103
+
Y aquí está el mismo ejemplo usando JSX:
104
104
105
105
<Sandpack>
106
106
@@ -127,11 +127,11 @@ export default function App() {
127
127
128
128
</Sandpack>
129
129
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.
131
131
132
-
<DeepDivetitle="What is a React element, exactly?">
132
+
<DeepDivetitle="Qué es exactamente un elemento React?">
133
133
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:
135
135
136
136
```js
137
137
// Slightly simplified
@@ -145,21 +145,21 @@ An element is a lightweight description of a piece of the user interface. For ex
145
145
}
146
146
```
147
147
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.**
149
149
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.
151
151
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.
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`.
163
163
164
164
```js
165
165
import { createElement } from'react';
@@ -173,31 +173,31 @@ function Greeting({ name }) {
173
173
}
174
174
```
175
175
176
-
[See more examples above.](#usage)
176
+
[Ver más ejemplos arriba.](#usage)
177
177
178
-
#### Parameters {/*parameters*/}
178
+
#### Parámetros {/*parameters*/}
179
179
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)).
181
181
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`.
183
183
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.
185
185
186
-
#### Returns {/*returns*/}
186
+
#### Devuelve {/*returns*/}
187
187
188
-
`createElement`returns a React element object with a few properties:
188
+
`createElement`devuelve un objecto React element con algunas propiedades:
189
189
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`.
194
194
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.
196
196
197
-
#### Caveats {/*caveats*/}
197
+
#### Advertencias {/*caveats*/}
198
198
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.
200
200
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).
202
202
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