Skip to content

Commit 0ab619d

Browse files
authored
translate(reference): img (#739) (#740)
Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
1 parent 9efe599 commit 0ab619d

1 file changed

Lines changed: 54 additions & 47 deletions

File tree

  • src/content/reference/react-dom/components

‎src/content/reference/react-dom/components/img.md‎

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
---
22
title: "<img>"
3+
translationStatus: ai-draft
34
---
45

6+
<Note>
7+
8+
Questa pagina è stata tradotta automaticamente e supervisionata da un maintainer. Un'ulteriore revisione da parte della community sarebbe comunque utile. [Migliora questa traduzione](https://github.com/reactjs/it.react.dev/edit/main/src/content/reference/react-dom/components/img.md).
9+
10+
</Note>
11+
512
<Intro>
613

7-
The [built-in browser `<img>` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) lets you embed an image.
14+
Il [componente browser integrato `<img>`](https://developer.mozilla.org/it/docs/Web/HTML/Element/img) ti permette di incorporare un'immagine.
815

916
```js
10-
<img src="photo.jpg" alt="A person walking through a park" />
17+
<img src="photo.jpg" alt="Una persona che cammina in un parco" />
1118
```
1219

1320
</Intro>
@@ -20,46 +27,46 @@ The [built-in browser `<img>` component](https://developer.mozilla.org/en-US/doc
2027

2128
### `<img>` {/*img*/}
2229

23-
To display an image, render the [built-in browser `<img>` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img).
30+
Per visualizzare un'immagine, renderizza il [componente browser integrato `<img>`](https://developer.mozilla.org/it/docs/Web/HTML/Element/img).
2431

2532
```js
26-
<img src="photo.jpg" alt="A person walking through a park" />
33+
<img src="photo.jpg" alt="Una persona che cammina in un parco" />
2734
```
2835

29-
[See more examples below.](#usage)
36+
[Vedi altri esempi sotto.](#usage)
3037

3138
#### Props {/*props*/}
3239

33-
`<img>` supports all [common element props.](/reference/react-dom/components/common#common-props)
34-
35-
* `alt`: a string. Specifies alternative text for the image. Use an empty string for a purely decorative image.
36-
* `crossOrigin`: a string. Specifies the [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) to use when fetching the image. The possible values are `anonymous` and `use-credentials`.
37-
* `decoding`: a string. Suggests whether the browser should wait to decode the image before presenting other content. The possible values are `async`, `sync`, and `auto` (the default).
38-
* `fetchPriority`: a string. Suggests a relative priority for fetching the image. The possible values are `high`, `low`, and `auto` (the default). During server rendering, `fetchPriority="low"` also prevents React from [automatically preloading the image.](#controlling-image-preloading-during-server-rendering)
39-
* `height`: a number or string. Specifies the rendered height of the image.
40-
* `loading`: a string. Specifies whether the browser should defer loading the image until it is near the viewport. The possible values are `eager` (the default) and `lazy`. Setting `loading="lazy"` prevents React from [automatically preloading the image.](#controlling-image-preloading-during-server-rendering)
41-
* `onError`: an [event handler](/reference/react-dom/components/common#event-handler) function. Fires when the image fails to load.
42-
* `onLoad`: an [event handler](/reference/react-dom/components/common#event-handler) function. Fires when the image finishes loading. Passing `onLoad` prevents React from [waiting for the image during a client-rendered View Transition update.](#waiting-for-an-image-during-a-view-transition)
43-
* `referrerPolicy`: a string. Specifies the [referrer information](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#referrerpolicy) to send when fetching the image.
44-
* `sizes`: a string. Specifies the image sizes for different page layouts. Used with `srcSet`.
45-
* `src`: a string. Specifies the URL of the image.
46-
* `srcSet`: a string. Specifies one or more candidate image sources for the browser to choose from.
47-
* `useMap`: a string. Associates the image with a [client-side image map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map).
48-
* `width`: a number or string. Specifies the rendered width of the image.
40+
`<img>` supporta tutte le [props comuni degli elementi.](/reference/react-dom/components/common#common-props)
41+
42+
* `alt`: una stringa. Specifica il testo alternativo dell'immagine. Usa una stringa vuota per un'immagine puramente decorativa.
43+
* `crossOrigin`: una stringa. Specifica la [policy CORS](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) da usare quando viene recuperata l'immagine. I valori possibili sono `anonymous` e `use-credentials`.
44+
* `decoding`: una stringa. Suggerisce se il browser dovrebbe attendere di decodificare l'immagine prima di presentare altro contenuto. I valori possibili sono `async`, `sync` e `auto` (il valore predefinito).
45+
* `fetchPriority`: una stringa. Suggerisce una priorità relativa per il recupero dell'immagine. I valori possibili sono `high`, `low` e `auto` (il valore predefinito). Durante la renderizzazione lato server, `fetchPriority="low"` impedisce anche a React di [precaricare automaticamente l'immagine.](#controlling-image-preloading-during-server-rendering)
46+
* `height`: un numero o una stringa. Specifica l'altezza con cui viene visualizzata l'immagine.
47+
* `loading`: una stringa. Specifica se il browser dovrebbe rinviare il caricamento dell'immagine finché non è vicina al viewport. I valori possibili sono `eager` (il valore predefinito) e `lazy`. Impostare `loading="lazy"` impedisce a React di [precaricare automaticamente l'immagine.](#controlling-image-preloading-during-server-rendering)
48+
* `onError`: una funzione [gestore di eventi](/reference/react-dom/components/common#event-handler). Scatta quando il caricamento dell'immagine fallisce.
49+
* `onLoad`: una funzione [gestore di eventi](/reference/react-dom/components/common#event-handler). Scatta quando il caricamento dell'immagine è completato. Passare `onLoad` impedisce a React di [attendere l'immagine durante un aggiornamento View Transition renderizzato lato client.](#waiting-for-an-image-during-a-view-transition)
50+
* `referrerPolicy`: una stringa. Specifica le [informazioni sul referrer](https://developer.mozilla.org/it/docs/Web/HTML/Element/img#referrerpolicy) da inviare quando viene recuperata l'immagine.
51+
* `sizes`: una stringa. Specifica le dimensioni dell'immagine per i diversi layout di pagina. Usata insieme a `srcSet`.
52+
* `src`: una stringa. Specifica l'URL dell'immagine.
53+
* `srcSet`: una stringa. Specifica una o più sorgenti candidate tra cui il browser può scegliere.
54+
* `useMap`: una stringa. Associa l'immagine a una [mappa immagine lato client](https://developer.mozilla.org/it/docs/Web/HTML/Element/map).
55+
* `width`: un numero o una stringa. Specifica la larghezza con cui viene visualizzata l'immagine.
4956

5057
#### Caveats {/*caveats*/}
5158

52-
* Do not pass an empty string to `src`. It may cause the browser to request the current page again. React warns in development and omits the attribute. To render no image, omit the `<img>` or pass `null` to `src`.
53-
* `<img>` cannot have children or use `dangerouslySetInnerHTML`. React throws an error if you pass either.
54-
* `fetchPriority="low"` does not stop React from waiting for the image to load and decode during a client-rendered View Transition update. Use `loading="lazy"` or an `onLoad` handler to opt out of that behavior.
59+
* Non passare una stringa vuota a `src`: potrebbe indurre il browser a richiedere di nuovo la pagina corrente. React mostra un avviso in sviluppo e omette l'attributo. Per non visualizzare alcuna immagine, ometti `<img>` o passa `null` a `src`.
60+
* `<img>` non può avere children né usare `dangerouslySetInnerHTML`. React solleva un errore se passi una delle due cose.
61+
* `fetchPriority="low"` non impedisce a React di attendere che l'immagine venga caricata e decodificata durante un aggiornamento View Transition renderizzato lato client. Usa `loading="lazy"` o un gestore `onLoad` per rinunciare a questo comportamento.
5562

5663
---
5764

5865
## Usage {/*usage*/}
5966

60-
### Displaying an image {/*displaying-an-image*/}
67+
### Visualizzare un'immagine {/*displaying-an-image*/}
6168

62-
Pass the image URL to `src` and a text description to `alt`:
69+
Passa l'URL dell'immagine a `src` e una descrizione testuale a `alt`:
6370

6471
<Sandpack>
6572

@@ -85,53 +92,53 @@ img {
8592

8693
</Sandpack>
8794

88-
Specify `width` and `height` when you know the image dimensions so the browser can reserve space before the image loads. For a decorative image, pass `alt=""` so that screen readers ignore it.
95+
Specifica `width` e `height` quando conosci le dimensioni dell'immagine, così il browser può riservare lo spazio prima che l'immagine venga caricata. Per un'immagine decorativa, passa `alt=""` in modo che gli screen reader la ignorino.
8996

9097
---
9198

92-
### Controlling image preloading during server rendering {/*controlling-image-preloading-during-server-rendering*/}
99+
### Controllare il precaricamento delle immagini durante la renderizzazione lato server {/*controlling-image-preloading-during-server-rendering*/}
93100

94-
During server rendering, React automatically generates a preload hint for an `<img>` by default. This can let the browser start fetching the image before it encounters the `<img>` in the rendered HTML.
101+
Durante la renderizzazione lato server, per impostazione predefinita React genera automaticamente un hint di preload per un `<img>`. Questo può permettere al browser di iniziare a recuperare l'immagine prima di incontrare l'`<img>` nell'HTML renderizzato.
95102

96-
Add `loading="lazy"` or `fetchPriority="low"` to an image that should not receive this hint:
103+
Aggiungi `loading="lazy"` o `fetchPriority="low"` a un'immagine che non dovrebbe ricevere questo hint:
97104

98105
```js
99106
function ProductPage() {
100107
return (
101108
<>
102-
<img src="hero.jpg" alt="Featured product" />
103-
<img src="thumbnail.jpg" alt="Related product" loading="lazy" />
104-
<img src="secondary.jpg" alt="Another product" fetchPriority="low" />
109+
<img src="hero.jpg" alt="Prodotto in evidenza" />
110+
<img src="thumbnail.jpg" alt="Prodotto correlato" loading="lazy" />
111+
<img src="secondary.jpg" alt="Un altro prodotto" fetchPriority="low" />
105112
</>
106113
);
107114
}
108115
```
109116

110-
In this example, React generates a preload hint only for `hero.jpg`. Depending on the server API or framework, React may render the equivalent of this element:
117+
In questo esempio, React genera un hint di preload solo per `hero.jpg`. A seconda dell'API del server o del framework, React potrebbe renderizzare l'equivalente di questo elemento:
111118

112119
```html
113120
<link rel="preload" as="image" href="hero.jpg" />
114121
```
115122

116-
React may instead provide the same hint in a `Link` response header. The other two images keep their `loading` and `fetchPriority` props in the rendered HTML, but React does not generate preload hints for them. The `loading="lazy"` prop asks the browser to defer loading an image until it approaches the viewport. The `fetchPriority="low"` prop allows the image to load immediately, but tells the browser to fetch it at a lower priority.
123+
React potrebbe invece fornire lo stesso hint nell'intestazione `Link` della risposta. Le altre due immagini mantengono le loro props `loading` e `fetchPriority` nell'HTML renderizzato, ma React non genera hint di preload per queste immagini. La prop `loading="lazy"` chiede al browser di rinviare il caricamento di un'immagine finché non si avvicina al viewport. La prop `fetchPriority="low"` permette all'immagine di caricarsi immediatamente, ma dice al browser di recuperarla con una priorità più bassa.
117124

118-
React also does not automatically preload an image when it is inside a `<picture>` or `<noscript>` element, or when its `src` or `srcSet` is a data URL.
125+
React inoltre non precarica automaticamente un'immagine quando si trova all'interno di un elemento `<picture>` o `<noscript>`, o quando il suo `src` o `srcSet` è un data URL.
119126

120-
If you render an image through a framework or a component library, consult its documentation for the default behavior. React decides whether to generate an automatic preload from the props of the underlying `<img>`. For example, an image component may add `loading="lazy"` by default and provide a separate option for explicitly preloading selected images.
127+
Se renderizzi un'immagine attraverso un framework o una libreria di componenti, consulta la sua documentazione per il comportamento predefinito. React decide se generare un precaricamento automatico in base alle props dell'`<img>` sottostante. Ad esempio, un componente immagine potrebbe aggiungere `loading="lazy"` per impostazione predefinita e fornire un'opzione separata per precaricare esplicitamente le immagini selezionate.
121128

122-
To create an explicit preload hint, call [`preload`](/reference/react-dom/preload).
129+
Per creare un hint di preload esplicito, chiama [`preload`](/reference/react-dom/preload).
123130

124131
---
125132

126-
### Waiting for an image during a View Transition {/*waiting-for-an-image-during-a-view-transition*/}
133+
### Attendere un'immagine durante una View Transition {/*waiting-for-an-image-during-a-view-transition*/}
127134

128-
During a client-rendered [`<ViewTransition>`](/reference/react/ViewTransition) update, React may wait for an image to load and decode before starting the animation. This applies when a new `<img>` with a non-empty `src` is rendered, or when an existing image's `src` or `srcSet` changes. The image must be inside the `<ViewTransition>` subtree and must not have `loading="lazy"` or an `onLoad` handler. React does not wait for images during synchronous updates.
135+
Durante un aggiornamento [`<ViewTransition>`](/reference/react/ViewTransition) renderizzato lato client, React potrebbe attendere che un'immagine si carichi e venga decodificata prima di avviare l'animazione. Questo si applica quando viene renderizzato un nuovo `<img>` con un `src` non vuoto, o quando `src` o `srcSet` di un'immagine esistente cambia. L'immagine deve trovarsi nel sottoalbero del `<ViewTransition>` e non deve avere `loading="lazy"` né un gestore `onLoad`. React non attende le immagini durante gli aggiornamenti sincroni.
129136

130-
When a Suspense boundary reveals streamed content inside a `<ViewTransition>`, React may also wait for visible images with a non-empty `src` that do not have `loading="lazy"`. React stops waiting after a timeout so that a slow image does not block the update indefinitely.
137+
Quando un boundary Suspense rivela contenuto in streaming all'interno di un `<ViewTransition>`, React potrebbe anche attendere le immagini visibili con un `src` non vuoto che non hanno `loading="lazy"`. React smette di attendere dopo un timeout, così che un'immagine lenta non blocchi l'aggiornamento all'infinito.
131138

132-
In this example, the Suspense boundary is wrapped in a `<ViewTransition>` and shows a profile skeleton until the portrait has loaded.
139+
In questo esempio, il boundary Suspense è avvolto in un `<ViewTransition>` e mostra un placeholder del profilo finché il ritratto non si è caricato.
133140

134-
For comparison, the second button inserts the same card directly into the DOM. The card appears immediately, and the browser displays the image after it loads:
141+
Per confronto, il secondo pulsante inserisce la stessa card direttamente nel DOM. La card appare immediatamente, e il browser visualizza l'immagine dopo che si è caricata:
135142

136143
<Sandpack>
137144

@@ -168,7 +175,7 @@ export default function App() {
168175
setSrc(freshImageUrl());
169176
});
170177
}}>
171-
Show profile
178+
Mostra profilo
172179
</button>
173180
{src && (
174181
<ViewTransition>
@@ -198,16 +205,16 @@ export default function VanillaProfile() {
198205
}
199206
return (
200207
<>
201-
<button onClick={show}>Show profile (direct DOM update)</button>
208+
<button onClick={show}>Mostra profilo (aggiornamento diretto del DOM)</button>
202209
<div ref={ref} />
203210
</>
204211
);
205212
}
206213
```
207214

208215
```js src/image.js hidden
209-
// Add a unique parameter so the image isn't cached,
210-
// and every run shows the loading state.
216+
// Aggiungi un parametro univoco così l'immagine non finisce in cache
217+
// e ogni esecuzione mostra lo stato di caricamento.
211218
export function freshImageUrl() {
212219
return 'https://react.dev/images/team/jack-pope.jpg?t=' + Date.now();
213220
}

0 commit comments

Comments
 (0)