From b4b198bf4a9b0371b70408d53a34772c406ead8f Mon Sep 17 00:00:00 2001 From: Samuele Piazzesi Date: Thu, 27 Apr 2023 12:24:38 +0200 Subject: [PATCH 1/7] translate js in jsx with curly braces content --- .../javascript-in-jsx-with-curly-braces.md | 111 +++++++++--------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/src/content/learn/javascript-in-jsx-with-curly-braces.md b/src/content/learn/javascript-in-jsx-with-curly-braces.md index 502916113..28dbdf192 100644 --- a/src/content/learn/javascript-in-jsx-with-curly-braces.md +++ b/src/content/learn/javascript-in-jsx-with-curly-braces.md @@ -1,25 +1,25 @@ --- -title: JavaScript in JSX with Curly Braces +title: JavaScript in JSX con le parentesi graffe --- -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 ti permette di scrivere codice HTML all'interno di un file JavaScript, mantenendo la logica di rendering e il contenuto nello stesso posto. A volte vorrai aggiungere un po' di logica JavaScript o fare riferimento a una proprietà dinamica all'interno di quel markup. In questa situazione, puoi usare le parentesi graffe nel tuo JSX per aprire una finestra su 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 +* Come passare stringhe con virgolette +* Come riferirti a una variabile JavaScript all'interno di JSX con le parentesi graffe +* Come chiamare una funzione JavaScript all'interno di JSX con le parentesi graffe +* Come passare oggetti JavaScript all'interno di JSX con le parentesi graffe -## Passing strings with quotes {/*passing-strings-with-quotes*/} +## Passare stringhe con le virgolette {/*passing-strings-with-quotes*/} -When you want to pass a string attribute to JSX, you put it in single or double quotes: +Quando vuoi passare un attributo stringa a JSX, mettilo tra virgolette singole o doppie: @@ -41,9 +41,10 @@ export default function Avatar() { -Here, `"https://i.imgur.com/7vQD0fPs.jpg"` and `"Gregorio Y. Zara"` are being passed as 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 `}`**: +qui, `"https://i.imgur.com/7vQD0fPs.jpg"` e `"Gregorio Y. Zara"` sono passati come stringhe. + +E se vuoi specificare dinamicamente il `src` o il testo `alt`? Puoi **usare un valore da JavaScript sostituendo `"` e `"` con `{` e `}`**: @@ -67,11 +68,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! +Nota la differenza tra `className="avatar"`, che specifica un nome di classe CSS `"avatar"` che rende l'immagine rotonda, e `src={avatar}` che legge il valore della variabile JavaScript chiamata `avatar`. Questo perché le parentesi graffe ti permettono di lavorare con JavaScript proprio lì nel tuo markup! -## Using curly braces: A window into the JavaScript world {/*using-curly-braces-a-window-into-the-javascript-world*/} +## Usare le parentesi graffe: una finestra nel mondo 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 è un modo speciale di scrivere JavaScript. Ciò significa che è possibile utilizzare JavaScript al suo interno, con le parentesi graffe `{ }`. L'esempio seguente dichiara prima un nome per lo scienziato, `name`, quindi lo incorpora con le parentesi graffe all'interno di `

`: @@ -86,9 +87,9 @@ export default function TodoList() { -Try changing the `name`'s value from `'Gregorio Y. Zara'` to `'Hedy Lamarr'`. See how the list title changes? +Prova a cambiare il valore di `name` da `'Gregorio Y. Zara'` a `'Hedy Lamarr'`. Vedi come cambia il titolo della lista? -Any JavaScript expression will work between curly braces, including function calls like `formatDate()`: +Qualsiasi espressione JavaScript funzionerà tra le parentesi graffe, inclusa la chiamata di funzioni come `formatDate()`: @@ -111,18 +112,18 @@ export default function TodoList() { -### Where to use curly braces {/*where-to-use-curly-braces*/} +### Dove utilizzare le parentesi graffe {/*where-to-use-curly-braces*/} -You can only use curly braces in two ways inside JSX: +Puoi usare le parentesi graffe solo in due modi all'interno di 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. **Come testo** direttamente all'interno di un tag JSX: `

{name}'s To Do List

` funziona, ma `<{tag}>Gregorio Y. Zara's To Do List` non funzionerà. +2. **Come attributi** immediatamente dopo il simbolo `=`: `src={avatar}` leggerà la variabile `avatar`, ma `src="{avatar}"` passerà la stringa `"{avatar}"`. -## Using "double curlies": CSS and other objects in JSX {/*using-double-curlies-css-and-other-objects-in-jsx*/} +## Usare le "doppie graffe": CSS and altri oggetti in 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 }}`. +In aggiunta alle stringhe, numeri e altre espressioni JavaScript, puoi anche passare oggetti in JSX. Gli oggetti sono anche indicati con le parentesi graffe, come `{ name: "Hedy Lamarr", inventions: 5 }`. Pertanto, per passare un oggetto JS in JSX, devi avvolgere l'oggetto in un'altra coppia di parentesi graffe: `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: +Potresti notarlo quando usi gli stili CSS in linea in JSX. React non richiede di utilizzare gli stili in linea (le classi CSS funzionano alla grande per la maggior parte dei casi). Ma quando hai bisogno di uno stile in linea, passi un oggetto all'attributo `style`: @@ -148,9 +149,9 @@ ul { padding: 20px 20px 20px 40px; margin: 0; } -Try changing the values of `backgroundColor` and `color`. +Prova a cambiare i valori di `backgroundColor` e `color`. -You can really see the JavaScript object inside the curly braces when you write it like this: +Puoi vedere effettivamente l'oggetto JavaScript all'interno delle parentesi graffe quando lo scrivi in questo modo: ```js {2-5}