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
Copy file name to clipboardExpand all lines: src/content/learn/render-and-commit.md
+48-48
Original file line number
Diff line number
Diff line change
@@ -1,44 +1,44 @@
1
1
---
2
-
title: Render and Commit
2
+
title: Renderizzare e Aggiornare
3
3
---
4
4
5
5
<Intro>
6
6
7
-
Before your components are displayed on screen, they must be rendered by React. Understanding the steps in this process will help you think about how your code executes and explain its behavior.
7
+
Prima che i tuoi componenti siano visualizzati sullo schermo, devono essere renderizzati da React. Comprendere i passaggi di questo processo ti aiuterà a pensare a come il tuo codice viene eseguito e a spiegare il suo comportamento.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*What rendering means in React
14
-
*When and why React renders a component
15
-
*The steps involved in displaying a component on screen
16
-
*Why rendering does not always produce a DOM update
13
+
*Cosa significa renderizzare in React
14
+
*Quando e perché React renderizza un componente
15
+
*I passaggi coinvolti necessari per visualizzare un componente sullo schermo
16
+
*Perché renderizzare non sempre produce un aggiornamento del DOM
17
17
18
18
</YouWillLearn>
19
19
20
-
Imagine that your components are cooks in the kitchen, assembling tasty dishes from ingredients. In this scenario, React is the waiter who puts in requests from customers and brings them their orders. This process of requesting and serving UI has three steps:
20
+
Immagina che i tuoi componenti siano chef in cucina, che assemblano piatti gustosi dagli ingredienti. In questo scenario, React è il cameriere che prende le richieste dai clienti e porta loro gli ordini. Questo processo di richiesta e servizio dell'interfaccia utente (UI) ha tre fasi:
21
21
22
-
1.**Triggering**a render (delivering the guest's order to the kitchen)
23
-
2.**Rendering**the component (preparing the order in the kitchen)
24
-
3.**Committing**to the DOM (placing the order on the table)
22
+
1.**Avviare**una renderizzazione (consegnare l'ordine del cliente alla cucina)
23
+
2.**Renderizzare**il componente (preparare l'ordine in cucina)
24
+
3.**Aggiornare**il DOM (mettere l'ordine sul tavolo)
25
25
26
26
<IllustrationBlocksequential>
27
27
<Illustrationcaption="Trigger"alt="React as a server in a restaurant, fetching orders from the users and delivering them to the Component Kitchen."src="/images/docs/illustrations/i_render-and-commit1.png" />
28
28
<Illustrationcaption="Render"alt="The Card Chef gives React a fresh Card component."src="/images/docs/illustrations/i_render-and-commit2.png" />
29
29
<Illustrationcaption="Commit"alt="React delivers the Card to the user at their table."src="/images/docs/illustrations/i_render-and-commit3.png" />
30
30
</IllustrationBlock>
31
31
32
-
## Step 1: Trigger a render {/*step-1-trigger-a-render*/}
32
+
## Passo 1: Avviare la renderizzazione {/*step-1-trigger-a-render*/}
33
33
34
-
There are two reasons for a component to render:
34
+
Ci sono due motivi per cui un componente deve eseguire la renderizzazione:
35
35
36
-
1.It's the component's **initial render.**
37
-
2.The component's (or one of its ancestors') **state has been updated.**
36
+
1.È la **renderizzazione iniziale** del componente.
37
+
2.Lo **state** del componente(o uno dei suoi antenati) **è stato aggiornato.**
38
38
39
-
### Initial render {/*initial-render*/}
39
+
### Renderizzazione iniziale {/*initial-render*/}
40
40
41
-
When your app starts, you need to trigger the initial render. Frameworks and sandboxes sometimes hide this code, but it's done by calling[`createRoot`](/reference/react-dom/client/createRoot)with the target DOM node, and then calling its `render`method with your component:
41
+
Quando l'applicazione viene avviata, è necessario avviare la renderizzazione iniziale. Le librerie e gli ambienti di sviluppo a volte nascondono questo codice, ma viene eseguita chiamando [`createRoot`](/reference/react-dom/client/createRoot)con il nodo DOM di destinazione, e quindi chiamando il suo metodo `render`con il componente:
42
42
43
43
<Sandpack>
44
44
@@ -55,36 +55,36 @@ export default function Image() {
55
55
return (
56
56
<img
57
57
src="https://i.imgur.com/ZF6s192.jpg"
58
-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
58
+
alt="'Floralis Genérica' di Eduardo Catalano: una gigantesca scultura floreale metallica con petali riflettenti."
59
59
/>
60
60
);
61
61
}
62
62
```
63
63
64
64
</Sandpack>
65
65
66
-
Try commenting out the `root.render()`call and see the component disappear!
66
+
Prova a commentare la chiamata `root.render()`e vedrai il componente scomparire!
67
67
68
-
### Re-renders when state updates {/*re-renders-when-state-updates*/}
68
+
### Renderizzare nuovamente quando lo state viene aggiornato{/*re-renders-when-state-updates*/}
69
69
70
-
Once the component has been initially rendered, you can trigger further renders by updating its state with the [`set` function.](/reference/react/useState#setstate)Updating your component's state automatically queues a render. (You can imagine these as a restaurant guest ordering tea, dessert, and all sorts of things after putting in their first order, depending on the state of their thirst or hunger.)
70
+
Una volta che il componente è inizialmente renderizzato, è possibile avviare ulteriori renderizzazioni aggiornando il suo state con la [funzione `set`.](/reference/react/useState#setstate)Aggiornare lo state del componente mette automaticamente in coda una renderizzazione (puoi immaginarlo come un ospite del ristorante che ordina tè, dessert e ogni sorta di cosa dopo aver effettuato il primo ordine, a seconda della sua sete o fame)
71
71
72
72
<IllustrationBlocksequential>
73
73
<Illustrationcaption="State update..."alt="React as a server in a restaurant, serving a Card UI to the user, represented as a patron with a cursor for their head. They patron expresses they want a pink card, not a black one!"src="/images/docs/illustrations/i_rerender1.png" />
74
74
<Illustrationcaption="...triggers..."alt="React returns to the Component Kitchen and tells the Card Chef they need a pink Card."src="/images/docs/illustrations/i_rerender2.png" />
75
75
<Illustrationcaption="...render!"alt="The Card Chef gives React the pink Card."src="/images/docs/illustrations/i_rerender3.png" />
76
76
</IllustrationBlock>
77
77
78
-
## Step 2: React renders your components {/*step-2-react-renders-your-components*/}
78
+
## Passo 2: React renderizza i tuoi componenti {/*step-2-react-renders-your-components*/}
79
79
80
-
After you trigger a render, React calls your components to figure out what to display on screen. **"Rendering" is React calling your components.**
80
+
Dopo aver avviato la renderizzazione, React richiama i tuoi componenti per capire cosa mostrare a schermo. **"Renderizzare" è il termine che indica React che richiama i tuoi componenti.**
81
81
82
-
***On initial render,** React will call the root component.
83
-
***For subsequent renders,** React will call the function component whose state update triggered the render.
82
+
***Durante il rendering iniziale,** React richiama il componente radice.
83
+
***Per le renderizzazioni successive,** React richiama il componente funzione il cui aggiornamento di state ha scatenato il rendering.
84
84
85
-
This process is recursive: if the updated component returns some other component, React will render _that_ component next, and if that component also returns something, it will render _that_ component next, and so on. The process will continue until there are no more nested components and React knows exactly what should be displayed on screen.
85
+
Questo processo è ricorsivo: se il componente aggiornato restituisce un altro componente, React renderizzerà _quel_ componente successivamente, e se quel componente restituisce a sua volta qualcosa, renderizzerà _quel_ componente successivamente, e cosi via. Il processo continua finché non ci sono più componenti annidati e React sa esattamente cosa mostrare a schermo.
86
86
87
-
In the following example, React will call `Gallery()`and`Image()`several times:
***During the initial render,** React will [create the DOM nodes](https://developer.mozilla.org/docs/Web/API/Document/createElement)for`<section>`, `<h1>`, and three `<img>` tags.
128
-
***During a re-render,** React will calculate which of their properties, if any, have changed since the previous render. It won't do anything with that information until the next step, the commit phase.
127
+
***Durante la renderizzazione iniziale,** React [creerà i nodi del DOM](https://developer.mozilla.org/docs/Web/API/Document/createElement)per`<section>`, `<h1>`, e tre tag `<img>`.
128
+
***Durante una renderizzazione successiva,** React calcolerà quali delle sue proprietà, se presenti, sono cambiate rispetto la renderizzazione precedente. Tuttavia, non farà nulla con queste informazioni fino alla prossima fase, la fase di commit.
129
129
130
130
<Pitfall>
131
131
132
-
Rendering must always be a [pure calculation](/learn/keeping-components-pure):
132
+
La renderizzazione deve sempre essere un [calcolo puro](/learn/keeping-components-pure):
133
133
134
-
***Same inputs, same output.**Given the same inputs, a component should always return the same JSX. (When someone orders a salad with tomatoes, they should not receive a salad with onions!)
135
-
***It minds its own business.**It should not change any objects or variables that existed before rendering. (One order should not change anyone else's order.)
134
+
***Stessi input, stessi output.**Dati gli stessi input, un componente dovrebbe sempre restituire lo stesso JSX. (Quando qualcuno ordina un'insalata con i pomodori, non dovrebbe ricevere un'insalata con le cipolle!)
135
+
***Si cura solo dei suoi affari**Non dovrebbe modificare oggetti o variabili che esistevano prima della renderizzazione. (Un ordine non dovrebbe cambiare l'ordine di nessun altro.)
136
136
137
-
Otherwise, you can encounter confusing bugs and unpredictable behavior as your codebase grows in complexity. When developing in "Strict Mode", React calls each component's function twice, which can help surface mistakes caused by impure functions.
137
+
Altrimenti, è possibile incontrare bug confusi e comportamenti imprevedibili man mano che il tuo codice diventa più complesso. Quando si sviluppa in Strict Mode, React chiama due volte la funzione di ogni componente, il che può aiutare a individuare errori causati da funzioni impure.
#### Ottimizzazione delle prestazioni {/*optimizing-performance*/}
144
144
145
-
The default behavior of rendering all components nested within the updated component is not optimal for performance if the updated component is very high in the tree. If you run into a performance issue, there are several opt-in ways to solve it described in the [Performance](https://reactjs.org/docs/optimizing-performance.html) section. **Don't optimize prematurely!**
145
+
Il comportamento predefinito di renderizzare tutti i componenti annidati all'interno del componente aggiornato non è ottimale in termini di prestazioni se il componente aggiornato è molto in alto nell'albero. Se si riscontra un problema di prestazioni, esistono diverse soluzioni favorite descritte nella sezione [Prestazioni](https://reactjs.org/docs/optimizing-performance.html). **Non ottimizzare prematuramente!**
146
146
147
147
</DeepDive>
148
148
149
-
## Step 3: React commits changes to the DOM {/*step-3-react-commits-changes-to-the-dom*/}
149
+
## Step 3: React aggiorna il DOM {/*step-3-react-commits-changes-to-the-dom*/}
150
150
151
-
After rendering (calling) your components, React will modify the DOM.
151
+
Dopo aver renderizzato (chiamato) i componenti, React aggiornerà il DOM.
152
152
153
-
***For the initial render,** React will use the[`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild)DOM API to put all the DOM nodes it has created on screen.
154
-
***For re-renders,** React will apply the minimal necessary operations (calculated while rendering!) to make the DOM match the latest rendering output.
153
+
***Per la renderizzazione iniziale,** React utilizzerà l'API DOM[`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild)per inserire tutti i nodi DOM creati sullo schermo.
154
+
***Per ri-renderizzare,** React applicherà solo le operazioni minime necessarie (calcolate durante il rendering!) per rendere il DOM uguale all'ultimo output di rendering.
155
155
156
-
**React only changes the DOM nodes if there's a difference between renders.**For example, here is a component that re-renders with different props passed from its parent every second. Notice how you can add some text into the `<input>`, updating its `value`, but the text doesn't disappear when the component re-renders:
156
+
**React cambia solo i nodi DOM se c'è una differenza tra le renderizzazioni.**Ad esempio, ecco un componente che si ri-renderizza con diverse props passate dal suo genitore ogni secondo. Notare come è possibile aggiungere del testo nell' `<input>` aggiornando il suo `value`, ma il testo non scompare quando il componente si ri-renderizza:
157
157
158
158
<Sandpack>
159
159
@@ -193,21 +193,21 @@ export default function App() {
193
193
194
194
</Sandpack>
195
195
196
-
This works because during this last step, React only updates the content of`<h1>`with the new`time`. It sees that the `<input>`appears in the JSX in the same place as last time, so React doesn't touch the `<input>`—or its`value`!
Questo funziona perché durante l'ultimo passaggio, React aggiorna solo il contenuto di`<h1>`con il nuovo`time`. Vede che l' `<input>`appare nel JSX nello stesso punto come l'ultima volta, quindi React non tocca `<input>`— o il suo`value`!
197
+
## Epilogo: Dipingere il browser {/*epilogue-browser-paint*/}
198
198
199
-
After rendering is done and React updated the DOM, the browser will repaint the screen. Although this process is known as "browser rendering", we'll refer to it as "painting" to avoid confusion throughout the docs.
199
+
Dopo che la renderizzazione viene eseguita e React ha aggiornato il DOM, il browser dipinge nuovamente la schermata. Sebbene questo processo sia noto come "renderizzazione del browser", lo chiameremo "dipingere" per evitare confusione in tutta la documentazione.
200
200
201
-
<Illustrationalt="A browser painting 'still life with card element'."src="/images/docs/illustrations/i_browser-paint.png" />
201
+
<Illustrationalt="Un browser che dipinge l'immagine 'still life with card element'."src="/images/docs/illustrations/i_browser-paint.png" />
202
202
203
203
<Recap>
204
204
205
-
*Any screen update in a React app happens in three steps:
205
+
*Ogni aggiornamento dello schermo in un'app React avviene in tre fasi:
206
206
1. Trigger
207
-
2.Render
207
+
2.Renderizzazione
208
208
3. Commit
209
-
*You can use Strict Mode to find mistakes in your components
210
-
* React does not touch the DOM if the rendering result is the same as last time
209
+
*Puoi usare la Strict Mode per trovare gli errori nei tuoi componenti
210
+
* React non aggiorna il DOM se il risultato della renderizzazione è lo stesso della volta precedente
0 commit comments