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
On the server, call `renderToString`to render your app to HTML.
29
+
En el servidor, llama a `renderToString`para renderizar tu aplicación a HTML.
30
30
31
31
```js
32
32
import { renderToString } from'react-dom/server';
33
33
34
34
consthtml=renderToString(<App />);
35
35
```
36
36
37
-
On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot)to make the server-generated HTML interactive.
37
+
En el cliente, llama a [`hydrateRoot`](/reference/react-dom/client/hydrateRoot)para hacer que el HTML generado por el servidor sea interactivo.
38
38
39
-
[See more examples below.](#usage)
39
+
[Ver más ejemplos a continuación.](#usage)
40
40
41
-
#### Parameters {/*parameters*/}
41
+
#### Parámetros {/*parameters*/}
42
42
43
-
*`reactNode`: A React node you want to render to HTML. For example, a JSX node like`<App />`.
43
+
*`reactNode`: Un nodo de React que deseas renderizar como HTML. Por ejemplo, un nodo JSX como`<App />`.
44
44
45
45
#### Returns {/*returns*/}
46
46
47
-
An HTML string.
47
+
Una cadena de caracteres HTML.
48
48
49
-
#### Caveats {/*caveats*/}
49
+
#### Advertencias {/*caveats*/}
50
50
51
-
*`renderToString`has limited Suspense support. If a component suspends, `renderToString`immediately sends its fallback as HTML.
51
+
*`renderToString`tiene un soporte limitado para Suspense. Si un componente suspende, `renderToString`inmediatamente envía su fallback como HTML.
52
52
53
-
*`renderToString`works in the browser, but using it in the client code is [not recommended.](#removing-rendertostring-from-the-client-code)
53
+
*`renderToString`funciona en el navegador, pero [no se recomienda](#removing-rendertostring-from-the-client-code) usarlo en el código del cliente.
54
54
55
55
---
56
56
57
-
## Usage {/*usage*/}
57
+
## Uso {/*usage*/}
58
58
59
-
### Rendering a React tree as HTML to a string {/*rendering-a-react-tree-as-html-to-a-string*/}
59
+
### Renderizar un árbol de React como HTML en una cadena de caracteres {/*rendering-a-react-tree-as-html-to-a-string*/}
60
60
61
-
Call `renderToString`to render your app to an HTML string which you can send with your server response:
61
+
Llama a `renderToString`para renderizar tu aplicación como una cadena de caracteres HTML que puedes enviar con la respuesta del servidor:
62
62
63
63
```js {5-6}
64
64
import { renderToString } from'react-dom/server';
65
65
66
-
//The route handler syntax depends on your backend framework
66
+
//La sintaxis del manejador de rutas depende de tu framework de backend.
67
67
app.use('/', (request, response) => {
68
68
consthtml=renderToString(<App />);
69
69
response.send(html);
70
70
});
71
71
```
72
72
73
-
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.
73
+
Esto producirá la salida HTML inicial no interactiva de tus componentes de React. En el cliente, deberás llamar a [`hydrateRoot`](/reference/react-dom/client/hydrateRoot)para *hidratar* ese HTML generado por el servidor y hacerlo interactivo.
74
74
75
75
76
76
<Pitfall>
77
77
78
-
`renderToString`does not support streaming or waiting for data. [See the alternatives.](#alternatives)
78
+
`renderToString`no es compatible con transmisión o espera de datos. [Ver alternativas.](#alternatives)
79
79
80
80
</Pitfall>
81
81
82
82
---
83
83
84
-
## Alternatives {/*alternatives*/}
84
+
## Alternativas {/*alternatives*/}
85
85
86
-
### Migrating from`renderToString`to a streaming method on the server {/*migrating-from-rendertostring-to-a-streaming-method-on-the-server*/}
86
+
### Migración de`renderToString`a un método de transmisión en el servidor {/*migrating-from-rendertostring-to-a-streaming-method-on-the-server*/}
87
87
88
-
`renderToString`returns a string immediately, so it does not support streaming or waiting for data.
88
+
`renderToString`devuelve una cadena de caracteres de inmediato, por lo que no admite transmisión (*streaming*) o espera de datos.
89
89
90
-
When possible, we recommend to use these fully-featured alternatives:
90
+
Cuando sea posible, recomendamos utilizar estas alternativas totalmente funcionales:
91
91
92
-
*If you use Node.js, use[`renderToPipeableStream`.](/reference/react-dom/server/renderToPipeableStream)
93
-
*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)
*Si utilizas Deno o una versión moderna de runtime con[Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API), utiliza[`renderToReadableStream`.](/reference/react-dom/server/renderToReadableStream)
94
94
95
-
You can continue using `renderToString`if your server environment does not support streams.
95
+
Puedes continuar utilizando `renderToString`si tu entorno de servidor no admite *streams*.
96
96
97
97
---
98
98
99
-
### Removing`renderToString`from the client code {/*removing-rendertostring-from-the-client-code*/}
99
+
### Eliminar`renderToString`del código del cliente {/*removing-rendertostring-from-the-client-code*/}
100
100
101
-
Sometimes, `renderToString`is used on the client to convert some component to HTML.
101
+
A veces, se usa `renderToString`en el cliente para convertir algún componente en HTML.
102
102
103
103
```js {1-2}
104
-
// 🚩 Unnecessary: using renderToString on the client
104
+
// 🚩 Innecesario: usar renderToString en el cliente
105
105
import { renderToString } from'react-dom/server';
106
106
107
107
consthtml=renderToString(<MyIcon />);
108
-
console.log(html); //For example, "<svg>...</svg>"
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:
111
+
Importar`react-dom/server`**en el cliente** aumenta innecesariamente el tamaño de tu paquete y debe evitarse. Si necesitas renderizar algún componente como HTML en el navegador, utiliza[`createRoot`](/reference/react-dom/client/createRoot)y lee el HTML desde el DOM:
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.
125
+
La llamada a [`flushSync`](/reference/react-dom/flushSync)es necesaria para que el DOM se actualice antes de leer su propiedad [`innerHTML.`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML)
126
126
127
127
---
128
128
129
-
## Troubleshooting {/*troubleshooting*/}
129
+
## Solución de problemas {/*troubleshooting*/}
130
130
131
-
### When a component suspends, the HTML always contains a fallback {/*when-a-component-suspends-the-html-always-contains-a-fallback*/}
131
+
### Cuando un componente se suspende, el HTML siempre contiene un fallback {/*when-a-component-suspends-the-html-always-contains-a-fallback*/}
132
132
133
-
`renderToString`does not fully support Suspense.
133
+
`renderToString`no es compatible completamente con Suspense.
134
134
135
-
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.
136
-
137
-
To solve this, use one of the [recommended streaming solutions.](#migrating-from-rendertostring-to-a-streaming-method-on-the-server) They can stream content in chunks as it resolves on the server so that the user sees the page being progressively filled in even before the client code loads.
135
+
Si algún componente se suspende (Por ejemplo, porque está definido con [`lazy`](/reference/react/lazy) o busca datos), `renderToString` no esperará a que se resuelva su contenido. En su lugar, `renderToString` encontrará el límite de [`<Suspense>`](/reference/react/Suspense) más cercano por encima y renderizará su prop `fallback` en el HTML. El contenido no aparecerá hasta que se cargue el código del cliente.
138
136
137
+
Para resolver esto, utiliza una de las [soluciones de streaming recomendadas.](#migrating-from-rendertostring-to-a-streaming-method-on-the-server) Pueden transmitir contenido en trozos a medida que se resuelve en el servidor para que el usuario vea cómo se rellena la página progresivamente antes de que se cargue el código del cliente.
0 commit comments