diff --git a/beta/src/pages/learn/javascript-in-jsx-with-curly-braces.md b/beta/src/pages/learn/javascript-in-jsx-with-curly-braces.md index 1b970c723..31c994783 100644 --- a/beta/src/pages/learn/javascript-in-jsx-with-curly-braces.md +++ b/beta/src/pages/learn/javascript-in-jsx-with-curly-braces.md @@ -4,22 +4,22 @@ title: JavaScript in JSX with Curly Braces -JSX lets you write HTML-like markup inside a JavaScript file, keeping rendering logic and content in the same place. Sometimes you will want to add a little JavaScript logic or reference a dynamic property inside that markup. In this situation, you can use curly braces in your JSX to open a window to JavaScript. +JSX te permite escribir marcas similares a HTML dentro de un archivo JavaScript, manteniendo la lógica de renderizado y el contenido en el mismo lugar. A veces vas a querer agregar un poco de lógica JavaScript o hacer referencia a una propiedad dinámica dentro de ese marcado. En esta situación, puedes usar llaves en tu JSX para abrir una ventana a JavaScript. -* How to pass strings with quotes -* How to reference a JavaScript variable inside JSX with curly braces -* How to call a JavaScript function inside JSX with curly braces -* How to use a JavaScript object inside JSX with curly braces +* Cómo pasar strings con comillas +* Cómo hacer referencia a una variable de JavaScript dentro de JSX con llaves +* Cómo llamar una funcion de JavaScript dentro de JSX con llaves +* Cómo usar un objeto de JavaScript dentro de JSX con llaves -## Passing strings with quotes {/*passing-strings-with-quotes*/} +## Pasando strings con comillas {/*passing-strings-with-quotes*/} -When you want to pass a string attribute to JSX, you put it in single or double quotes: +Cuando desees pasar un atributo string a JSX, lo pones entre comillas simples o dobles: @@ -41,9 +41,9 @@ export default function Avatar() { -Here, `"https://i.imgur.com/7vQD0fPs.jpg"` and `"Gregorio Y. Zara"` are being passed as strings. +Aquí, `"https://i.imgur.com/7vQD0fPs.jpg"` y `"Gregorio Y. Zara"` están siendo pasados como strings. -But what if you want to dynamically specify the `src` or `alt` text? You could **use a value from JavaScript by replacing `"` and `"` with `{` and `}`**: +Pero, ¿qué sucede si quieres especificar dinámicamente el texto `src` o `alt`? Puedes **usar un valor de JavaScript reemplazando `"` y `"` con `{` y `}`**: @@ -67,11 +67,11 @@ export default function Avatar() { -Notice the difference between `className="avatar"`, which specifies an `"avatar"` CSS class name that makes the image round, and `src={avatar}` that reads the value of the JavaScript variable called `avatar`. That's because curly braces let you work with JavaScript right there in your markup! +Observa la diferencia entre `className="avatar"`, que especifica un nombre de clase CSS `"avatar"` que hace que la imagen sea redonda, y `src={avatar}` que lee el valor de una variable JavaScript llamada `avatar`. ¡Eso es porque las llaves te permiten trabajar con JavaScript allí mismo en tu marcado!. -## Using curly braces: A window into the JavaScript world {/*using-curly-braces-a-window-into-the-javascript-world*/} +## Usando llaves: Una ventana al mundo de JavaScript {/*using-curly-braces-a-window-into-the-javascript-world*/} -JSX is a special way of writing JavaScript. That means it’s possible to use JavaScript inside it—with curly braces `{ }`. The example below first declares a name for the scientist, `name`, then embeds it with curly braces inside the `

`: +JSX es una forma especial de escribir JavaScript. Esto significa que es posible usar JavaScript dentro el, con llaves `{ }`. El siguiente ejemplo declara primero declara un nombre para el científico, `name`, luego lo incrusta con llaves dentro de `

`: @@ -86,9 +86,9 @@ export default function TodoList() { -Try changing `name`'s value from `'Gregorio Y. Zara'` to `'Hedy Lamarr'`. See how the To Do List title changes? +Intenta cambiar el valor de `name` de `'Gregorio Y. Zara'` a `'Hedy Lamarr'`. ¿Ves cómo cambia el título de la lista de tareas pendientes? -Any JavaScript expression will work between curly braces, including function calls like `formatDate()`: +Cualquier expresión JavaScript funcionará entre llaves, incluidas las llamadas a funciones como `formatDate()`: @@ -111,18 +111,18 @@ export default function TodoList() { -### Where to use curly braces {/*where-to-use-curly-braces*/} +### Dónde usar llaves {/*where-to-use-curly-braces*/} -You can only use curly braces in two ways inside JSX: +Solo puedes usar llaves de dos maneras dentro de JSX: -1. **As text** directly inside a JSX tag: `

{name}'s To Do List

` works, but `<{tag}>Gregorio Y. Zara's To Do List` will not. -2. **As attributes** immediately following the `=` sign: `src={avatar}` will read the `avatar` variable, but `src="{avatar}"` will pass the string `{avatar}`. +1. **Como texto** directamente dentro de una etiqueta JSX: `

{name}'s To Do List

` funciona, pero `<{tag}>Gregorio Y. Zara's To Do List` no lo hará. +2. **Como atributos** inmediatamente después del signo `=`: `src={avatar}` leerá la variable `avatar`, pero `src="{avatar}"` pasará el string `{avatar}`. -## Using "double curlies": CSS and other objects in JSX {/*using-double-curlies-css-and-other-objects-in-jsx*/} +## Usando "llaves dobles": CSS y otros objetos en JSX {/*using-double-curlies-css-and-other-objects-in-jsx*/} -In addition to strings, numbers, and other JavaScript expressions, you can even pass objects in JSX. Objects are also denoted with curly braces, like `{ name: "Hedy Lamarr", inventions: 5 }`. Therefore, to pass a JS object in JSX, you must wrap the object in another pair of curly braces: `person={{ name: "Hedy Lamarr", inventions: 5 }}`. +Además de strings, números, y otras expresiones de JavaScript, incluso puedes pasar objetos en JSX. Los objetos también se indican con llaves, como `{ name: "Hedy Lamarr", inventions: 5 }`. Por lo tanto, para pasar un objeto de JavaScript en JSX, debes envolver el objeto en otro par de llaves: `person={{ name: "Hedy Lamarr", inventions: 5 }}`. -You may see this with inline CSS styles in JSX. React does not require you to use inline styles (CSS classes work great for most cases). But when you need an inline style, you pass an object to the `style` attribute: +Puedes ver esto con estilos CSS en línea en JSX. React no requiere que uses estilos en línea (las clases CSS funcionan muy bien en la mayoría de los casos). Pero cuando necesites un estilo en línea, pasa un objeto al atributo `style`: @@ -148,9 +148,9 @@ ul { padding: 20px 20px 20px 40px; margin: 0; } -Try changing the values of `backgroundColor` and `color`. +Intenta cambiar los valores de `backgroundColor` y `color`. -You can really see the JavaScript object inside the curly braces when you write it like this: +Realmente puedes ver el objeto JavaScript dentro de las llaves cuando lo escribes así: ```js {2-5}