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
{{ message }}
Repository navigation
Commit c69bc79
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/flushSync.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ Nella maggior parte dei casi, `flushSync` può essere evitato. Usa `flushSync` c
59
59
#### Caveats {/*caveats*/}
60
60
61
61
*`flushSync` può compromettere significativamente le prestazioni. Usalo con parsimonia.
62
-
*`flushSync` può forzare i confini Suspense in sospeso a mostrare il loro stato `fallback`.
62
+
*`flushSync` può forzare i confini Suspense in sospeso a mostrare il `fallback`.
63
63
*`flushSync` può eseguire Effetti in sospeso e applicare in modo sincrono tutti gli aggiornamenti che contengono prima di restituire il controllo.
64
64
*`flushSync` può svuotare aggiornamenti al di fuori della callback quando necessario per svuotare gli aggiornamenti all'interno della callback. Ad esempio, se ci sono aggiornamenti in sospeso da un click, React potrebbe svuotarli prima di svuotare gli aggiornamenti all'interno della callback.
65
65
@@ -133,7 +133,7 @@ Senza `flushSync`, la finestra di dialogo di stampa mostrerà `isPrinting` come
133
133
134
134
<Pitfall>
135
135
136
-
`flushSync` può compromettere significativamente le prestazioni e può forzare in modo imprevisto i confini Suspense in sospeso a mostrare il loro stato fallback.
136
+
`flushSync` può compromettere significativamente le prestazioni e può forzare in modo imprevisto i confini Suspense in sospeso a mostrare il `fallback`.
137
137
138
138
Nella maggior parte dei casi, `flushSync` può essere evitato, quindi usalo come ultima risorsa.
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/server/renderToString.md).
9
-
10
-
</Note>
11
-
12
5
<Pitfall>
13
6
14
-
`renderToString`non supporta lo streaming né l'attesa dei dati. [Vedi le alternative.](#alternatives)
7
+
`renderToString`does not support streaming or waiting for data. [See the alternatives.](#alternatives)
15
8
16
9
</Pitfall>
17
10
18
11
<Intro>
19
12
20
-
`renderToString`renderizza un albero React in una stringa HTML.
13
+
`renderToString`renders a React tree to an HTML string.
21
14
22
15
```js
23
16
consthtml=renderToString(reactNode, options?)
@@ -33,105 +26,105 @@ const html = renderToString(reactNode, options?)
Sul server, chiama`renderToString`per renderizzare la tua app in HTML.
29
+
On the server, call`renderToString`to render your app to HTML.
37
30
38
31
```js
39
32
import { renderToString } from'react-dom/server';
40
33
41
34
consthtml=renderToString(<App />);
42
35
```
43
36
44
-
Sul client, chiama [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) per idratare l'HTML generato sul server.
37
+
On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to make the server-generated HTML interactive.
45
38
46
-
[Vedi altri esempi sotto.](#usage)
39
+
[See more examples below.](#usage)
47
40
48
41
#### Parameters {/*parameters*/}
49
42
50
-
* `reactNode`: Un nodo React che vuoi renderizzare in HTML. Ad esempio, un nodo JSX come`<App />`.
43
+
* `reactNode`: A React node you want to render to HTML. For example, a JSX node like`<App />`.
51
44
52
-
* **optional** `options`: Un oggetto per la renderizzazione sul server.
53
-
* **optional** `identifierPrefix`: Un prefisso stringa che React usa per gli ID generati da [`useId`.](/reference/react/useId) Utile per evitare conflitti quando usi più root sulla stessa pagina. Deve essere lo stesso prefisso passato a [`hydrateRoot`.](/reference/react-dom/client/hydrateRoot#parameters)
45
+
* **optional** `options`: An object for server render.
46
+
* **optional** `identifierPrefix`: A string prefix React uses for IDs generated by [`useId`.](/reference/react/useId) Useful to avoid conflicts when using multiple roots on the same page. Must be the same prefix as passed to [`hydrateRoot`.](/reference/react-dom/client/hydrateRoot#parameters)
54
47
55
48
#### Returns {/*returns*/}
56
49
57
-
Una stringa HTML.
50
+
An HTML string.
58
51
59
52
#### Caveats {/*caveats*/}
60
53
61
-
* `renderToString`ha un supporto limitato a Suspense. Se un componente sospende, `renderToString`invia immediatamente il suo fallback come HTML.
54
+
* `renderToString`has limited Suspense support. If a component suspends, `renderToString`immediately sends its fallback as HTML.
62
55
63
-
* `renderToString`funziona nel browser, ma usarlo nel codice client [non è consigliato.](#removing-rendertostring-from-the-client-code)
56
+
* `renderToString`works in the browser, but using it in the client code is [not recommended.](#removing-rendertostring-from-the-client-code)
64
57
65
58
---
66
59
67
60
## Usage {/*usage*/}
68
61
69
-
### Renderizzare un albero React come HTML in una stringa {/*rendering-a-react-tree-as-html-to-a-string*/}
62
+
### Rendering a React tree as HTML to a string {/*rendering-a-react-tree-as-html-to-a-string*/}
70
63
71
-
Chiama`renderToString`per renderizzare la tua app in una stringa HTML che puoi inviare con la risposta del server:
64
+
Call`renderToString`to render your app to an HTML string which you can send with your server response:
72
65
73
66
```js {5-6}
74
67
import { renderToString } from'react-dom/server';
75
68
76
-
//La sintassi del route handler dipende dal tuo framework backend
69
+
//The route handler syntax depends on your backend framework
77
70
app.use('/', (request, response) => {
78
71
consthtml=renderToString(<App />);
79
72
response.send(html);
80
73
});
81
74
```
82
75
83
-
Questo produrrà l'output HTML iniziale non interattivo dei tuoi componenti React. Sul client, dovrai chiamare [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) per *idratare* quell'HTML generato sul server e renderlo interattivo.
76
+
This will produce the initial non-interactive HTML output of your React components. On the client, you will need to call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to *hydrate* that server-generated HTML and make it interactive.
84
77
85
78
86
79
<Pitfall>
87
80
88
-
`renderToString`non supporta lo streaming né l'attesa dei dati. [Vedi le alternative.](#alternatives)
81
+
`renderToString`does not support streaming or waiting for data. [See the alternatives.](#alternatives)
89
82
90
83
</Pitfall>
91
84
92
85
---
93
86
94
87
## Alternatives {/*alternatives*/}
95
88
96
-
### Migrare da`renderToString`a una renderizzazione in streaming sul server {/*migrating-from-rendertostring-to-a-streaming-method-on-the-server*/}
89
+
### Migrating from`renderToString`to a streaming render on the server {/*migrating-from-rendertostring-to-a-streaming-method-on-the-server*/}
97
90
98
-
`renderToString`restituisce una stringa immediatamente, quindi non supporta lo streaming del contenuto man mano che viene caricato.
91
+
`renderToString`returns a string immediately, so it does not support streaming content as it loads.
99
92
100
-
Quando possibile, consigliamo di usare queste alternative complete:
93
+
When possible, we recommend using these fully-featured alternatives:
101
94
102
-
* Se usi Node.js, usa [`renderToPipeableStream`.](/reference/react-dom/server/renderToPipeableStream)
103
-
* Se usi Deno o un moderno edge runtime con [Web Streams](https://developer.mozilla.org/it/docs/Web/API/Streams_API), usa [`renderToReadableStream`.](/reference/react-dom/server/renderToReadableStream)
95
+
* If you use Node.js, use [`renderToPipeableStream`.](/reference/react-dom/server/renderToPipeableStream)
96
+
* If you use Deno or a modern edge runtime with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API), use [`renderToReadableStream`.](/reference/react-dom/server/renderToReadableStream)
104
97
105
-
Puoi continuare a usare`renderToString`se il tuo ambiente server non supporta gli stream.
98
+
You can continue using`renderToString`if your server environment does not support streams.
106
99
107
100
---
108
101
109
-
### Migrare da`renderToString`a un prerender statico sul server {/*migrating-from-rendertostring-to-a-static-prerender-on-the-server*/}
102
+
### Migrating from`renderToString`to a static prerender on the server {/*migrating-from-rendertostring-to-a-static-prerender-on-the-server*/}
110
103
111
-
`renderToString`restituisce una stringa immediatamente, quindi non supporta l'attesa del caricamento dei dati per la generazione di HTML statico.
104
+
`renderToString`returns a string immediately, so it does not support waiting for data to load for static HTML generation.
112
105
113
-
Consigliamo di usare queste alternative complete:
106
+
We recommend using these fully-featured alternatives:
114
107
115
-
* Se usi Node.js, usa [`prerenderToNodeStream`.](/reference/react-dom/static/prerenderToNodeStream)
116
-
* Se usi Deno o un moderno edge runtime con [Web Streams](https://developer.mozilla.org/it/docs/Web/API/Streams_API), usa [`prerender`.](/reference/react-dom/static/prerender)
108
+
* If you use Node.js, use [`prerenderToNodeStream`.](/reference/react-dom/static/prerenderToNodeStream)
109
+
* If you use Deno or a modern edge runtime with [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API), use [`prerender`.](/reference/react-dom/static/prerender)
117
110
118
-
Puoi continuare a usare`renderToString`se il tuo ambiente di generazione di siti statici non supporta gli stream.
111
+
You can continue using`renderToString`if your static site generation environment does not support streams.
### Removing`renderToString`from the client code {/*removing-rendertostring-from-the-client-code*/}
123
116
124
-
A volte, `renderToString`viene usato sul client per convertire un componente in HTML.
117
+
Sometimes, `renderToString`is used on the client to convert some component to HTML.
125
118
126
119
```js {1-2}
127
-
// 🚩 Non necessario: usare renderToString sul client
120
+
// 🚩 Unnecessary: using renderToString on the client
128
121
import { renderToString } from'react-dom/server';
129
122
130
123
consthtml=renderToString(<MyIcon />);
131
-
console.log(html); //Ad esempio, "<svg>...</svg>"
124
+
console.log(html); //For example, "<svg>...</svg>"
132
125
```
133
126
134
-
Importare`react-dom/server` **sul client** aumenta inutilmente la dimensione del bundle e va evitato. Se devi renderizzare un componente in HTML nel browser, usa [`createRoot`](/reference/react-dom/client/createRoot) e leggi l'HTML dal DOM:
127
+
Importing`react-dom/server` **on the client** unnecessarily increases your bundle size and should be avoided. If you need to render some component to HTML in the browser, use [`createRoot`](/reference/react-dom/client/createRoot) and read HTML from the DOM:
console.log(div.innerHTML); //For example, "<svg>...</svg>"
146
139
```
147
140
148
-
La chiamata a [`flushSync`](/reference/react-dom/flushSync) è necessaria affinché il DOM venga aggiornato prima di leggere la proprietà [`innerHTML`](https://developer.mozilla.org/it/docs/Web/API/Element/innerHTML).
141
+
The [`flushSync`](/reference/react-dom/flushSync) call is necessary so that the DOM is updated before reading its [`innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) property.
149
142
150
143
---
151
144
152
145
## Troubleshooting {/*troubleshooting*/}
153
146
154
-
### Quando un componente sospende, l'HTML contiene sempre un fallback {/*when-a-component-suspends-the-html-always-contains-a-fallback*/}
147
+
### When a component suspends, the HTML always contains a fallback {/*when-a-component-suspends-the-html-always-contains-a-fallback*/}
155
148
156
-
`renderToString`non supporta completamente Suspense.
149
+
`renderToString`does not fully support Suspense.
157
150
158
-
Se un componente sospende (ad esempio, perché è definito con [`lazy`](/reference/react/lazy) o recupera dati), `renderToString`non attenderà che il suo contenuto venga risolto. Invece, `renderToString`troverà il confine [`<Suspense>`](/reference/react/Suspense) più vicino sopra di esso e renderizzerà la sua prop `fallback`nell'HTML. Il contenuto non apparirà finché non viene caricato il codice client.
151
+
If some component suspends (for example, because it's defined with [`lazy`](/reference/react/lazy) or fetches data), `renderToString`will not wait for its content to resolve. Instead, `renderToString`will find the closest [`<Suspense>`](/reference/react/Suspense) boundary above it and render its `fallback`prop in the HTML. The content will not appear until the client code loads.
159
152
160
-
Per risolvere, usa una delle [soluzioni di streaming consigliate.](#alternatives) Per la renderizzazione sul server, possono fare streaming del contenuto a chunk man mano che viene risolto sul server, così l'utente vede la pagina riempirsi progressivamente prima che venga caricato il codice client. Per la generazione di siti statici, possono attendere che tutto il contenuto venga risolto prima di generare l'HTML statico.
153
+
To solve this, use one of the [recommended streaming solutions.](#alternatives) For server side rendering, they can stream content in chunks as it resolves on the server so that the user sees the page being progressively filled in before the client code loads. For static site generation, they can wait for all the content to resolve before generating the static HTML.
0 commit comments