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/reference/react-dom/client/hydrateRoot.md
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,9 +201,9 @@ O React se recupera de alguns erros de hidratação, mas **você precisa corrig
201
201
202
202
---
203
203
204
-
### Hydrating an entire document {/*hydrating-an-entire-document*/}
204
+
### Hidratando um documento inteiro {/*hydrating-an-entire-document*/}
205
205
206
-
Apps fully built with React can render the entire document as JSX, including the [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html) tag:
206
+
Aplicações totalmente construídas com React podem renderizar o documento inteiro como JSX, incluindo o [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html) tag:
207
207
208
208
```js {3,13}
209
209
functionApp() {
@@ -223,7 +223,7 @@ function App() {
223
223
}
224
224
```
225
225
226
-
To hydrate the entire document, pass the [`document`](https://developer.mozilla.org/en-US/docs/Web/API/Window/document) global as the first argument to`hydrateRoot`:
226
+
Para hidratar o documento inteiro, passe o [`document`](https://developer.mozilla.org/en-US/docs/Web/API/Window/document) global como primeiro argumento para`hydrateRoot`:
### Suprimindo erros inevitáveis de incompatibilidade de hidratação {/*suppressing-unavoidable-hydration-mismatch-errors*/}
238
238
239
-
If a single element’s attribute or text content is unavoidably different between the server and the client (for example, a timestamp), you may silence the hydration mismatch warning.
239
+
Se um simples atributo do elemento ou conteúdo de texto inevitavelmente conter diferenças entre o servidor e o cliente (por examplo, um timestamp), você poderá silenciar o aviso de diferença de hidratação.
240
240
241
-
To silence hydration warnings on an element, add`suppressHydrationWarning={true}`:
241
+
Para silenciar avisos de hidratação em um elemento, adicione`suppressHydrationWarning={true}`:
242
242
243
243
<Sandpack>
244
244
@@ -270,13 +270,13 @@ export default function App() {
270
270
271
271
</Sandpack>
272
272
273
-
This only works one level deep, and is intended to be an escape hatch. Don’t overuse it. Unless it’s text content, React still won’t attempt to patch it up, so it may remain inconsistent until future updates.
273
+
Somente funciona em um nível de profundidade, e é para ser usado como uma saída de emergência. Não abuse desse recurso. A menos que seja conteúdo de texto, o React ainda não tentará corrigi-lo, portanto pode permanecer inconsistente até atualizações futuras.
274
274
275
275
---
276
276
277
-
### Handling different client and server content {/*handling-different-client-and-server-content*/}
277
+
### Tratando diferenças de conteúdo entre cliente e servidor {/*handling-different-client-and-server-content*/}
278
278
279
-
If you intentionally need to render something different on the server and the client, you can do a two-pass rendering. Components that render something different on the client can read a [state variable](/reference/react/useState) like`isClient`, which you can set to `true`in an [Effect](/reference/react/useEffect):
279
+
Se você intecionalmente precisa renderizar algo diferente no servidor e no cliente, você pode fazer uma renderização de dois passos. Componentes que renderizam algo diferente no cliente pode ler um [state variable](/reference/react/useState) como`isClient`, o qual você pode definir como `true`em um [Effect](/reference/react/useEffect):
280
280
281
281
<Sandpack>
282
282
@@ -316,21 +316,21 @@ export default function App() {
316
316
317
317
</Sandpack>
318
318
319
-
This way the initial render pass will render the same content as the server, avoiding mismatches, but an additional pass will happen synchronously right after hydration.
319
+
Dessa forma a renderização inicial passará a renderizar o mesmo conteúdo do servidor, evitando diferenças, mas um passo adicional acontecerá de forma síncrona logo após a hidratação.
320
320
321
321
<Pitfall>
322
322
323
-
This approach makes hydration slower because your components have to render twice. Be mindful of the user experience on slow connections. The JavaScript code may load significantly later than the initial HTML render, so rendering a different UI immediately after hydration may also feel jarring to the user.
323
+
Essa abordagem deixa a hidratação mais vagarosa porque seus componentes terão que renderizar duas vezes. Fique atento a experiência do usuário com conexões lentas. O código JavaScript pode atrasar significantemente seu carregamento comparado com a renderização inicial do HTML, então renderizar uma UI diferente imediatamente após hidratação pode também ser prejudicial para o usuário.
324
324
325
325
</Pitfall>
326
326
327
327
---
328
328
329
-
### Updating a hydrated root component {/*updating-a-hydrated-root-component*/}
329
+
### Atualizando um componente raiz hidratado {/*updating-a-hydrated-root-component*/}
330
330
331
-
After the root has finished hydrating, you can call [`root.render`](#root-render) to update the root React component. **Unlike with [`createRoot`](/reference/react-dom/client/createRoot), you don't usually need to do this because the initial content was already rendered as HTML.**
331
+
Após a finalização da hidratação da raiz, você pode chamar [`root.render`](#root-render) para atualizar o componente raiz do React. **Diferente de [`createRoot`](/reference/react-dom/client/createRoot), você não precisa frequentemente fazer isso porque o conteúdo inicial já renderizou como HTML.**
332
332
333
-
If you call`root.render`at some point after hydration, and the component tree structure matches up with what was previously rendered, React will [preserve the state.](/learn/preserving-and-resetting-state) Notice how you can type in the input, which means that the updates from repeated `render`calls every second in this example are not destructive:
333
+
Se você chamar`root.render`em algum ponto após a hidratação, e a estrutura do componente árvore coincidir com o que foi previamente renderizado, o React [preservará o state.](/learn/preserving-and-resetting-state) Note como você pode escrever no campo de texto, o que significa que a atualização de repetidos `render`chamados cada segundo nesse exemplo não são destrutivos:
334
334
335
335
<Sandpack>
336
336
@@ -372,17 +372,17 @@ export default function App({counter}) {
372
372
373
373
</Sandpack>
374
374
375
-
It is uncommon to call [`root.render`](#root-render) on a hydrated root. Usually, you'll [update state](/reference/react/useState) inside one of the components instead.
375
+
É incomum chamar [`root.render`](#root-render) para uma raiz hidratada. Ao invés disso, usualmente, você [atualizará o state](/reference/react/useState) dentro de um dos componentes.
376
376
377
-
### Show a dialog for uncaught errors {/*show-a-dialog-for-uncaught-errors*/}
377
+
### Mostrando diálogo para erros não interceptados {/*show-a-dialog-for-uncaught-errors*/}
378
378
379
379
<Canary>
380
380
381
-
`onUncaughtError`is only available in the latest React Canary release.
381
+
`onUncaughtError`só está disponível no último release do React Canary.
382
382
383
383
</Canary>
384
384
385
-
By default, React will log all uncaught errors to the console. To implement your own error reporting, you can provide the optional`onUncaughtError`root option:
385
+
Por padrão, React imprimirá todos os log's de erros não interceptados no console. Para implementar seu prórpio relatório de erros, você pode definir o opcional`onUncaughtError`para raiz:
### Mostrando erros de Error Boundary {/*displaying-error-boundary-errors*/}
630
630
631
631
<Canary>
632
632
633
-
`onCaughtError`is only available in the latest React Canary release.
633
+
`onCaughtError`só está disponível na última release do React Canary.
634
634
635
635
</Canary>
636
636
637
-
By default, React will log all errors caught by an Error Boundary to`console.error`. To override this behavior, you can provide the optional`onCaughtError`root option for errors caught by an [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary):
637
+
Por padrão, React impriirá todos os log's de erros interceptados por um Error Boundary no`console.error`. Para mudar esse comportmento, você pode definir o opcional`onCaughtError`opção de raiz para erros interceptados por [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary):
The <CodeStep step={1}>onCaughtError</CodeStep> option is a function called with two arguments:
658
+
A opção <CodeStep step={1}>onCaughtError</CodeStep> é uma função que possui dois argumentos:
659
659
660
-
1. The <CodeStep step={2}>error</CodeStep> that was caught by the boundary.
661
-
2. An <CodeStep step={3}>errorInfo</CodeStep> object that contains the <CodeStep step={4}>componentStack</CodeStep> of the error.
660
+
1. O <CodeStep step={2}>error</CodeStep> que foi interceptado pelo boundary.
661
+
2. um objeto <CodeStep step={3}>errorInfo</CodeStep> que contém o <CodeStep step={4}>componentStack</CodeStep> do erro.
662
662
663
-
You can use the `onCaughtError`root option to display error dialogs or filter known errors from logging:
663
+
Você pode usar a opção da raiz `onCaughtError`para mostrar diálogos de erro ou filtrar erros conhecidos do log:
664
664
665
665
<Sandpack>
666
666
@@ -913,9 +913,9 @@ function Throw({error}) {
913
913
914
914
</Sandpack>
915
915
916
-
### Show a dialog for recoverable hydration mismatch errors {/*show-a-dialog-for-recoverable-hydration-mismatch-errors*/}
916
+
### Mostrar um diálogo para erros recuperáveis de diferença de hidratação {/*show-a-dialog-for-recoverable-hydration-mismatch-errors*/}
917
917
918
-
When React encounters a hydration mismatch, it will automatically attempt to recover by rendering on the client. By default, React will log hydration mismatch errors to `console.error`. To override this behavior, you can provide the optional`onRecoverableError`root option:
918
+
Quando o React encontra uma diferença de hidratação, ele automaticamente tentará recuperar renderizando no cliente. Por padrão, o React imprimirá o log de erros de diferença de hidratação no `console.error`. Para mudar esse comportamento, você pode definir o opcional`onRecoverableError`opção da raiz:
The <CodeStep step={1}>onRecoverableError</CodeStep> option is a function called with two arguments:
939
+
A opção <CodeStep step={1}>onRecoverableError</CodeStep> é uma função com dois argumentos:
940
940
941
-
1. The <CodeStep step={2}>error</CodeStep> React throws. Some errors may include the original cause as <CodeStep step={3}>error.cause</CodeStep>.
942
-
2. An <CodeStep step={4}>errorInfo</CodeStep> object that contains the <CodeStep step={5}>componentStack</CodeStep> of the error.
941
+
1. O <CodeStep step={2}>error</CodeStep> lançado pelo React. Alguns erros podem incluir a causa original como <CodeStep step={3}>error.cause</CodeStep>.
942
+
2. Um objeto <CodeStep step={4}>errorInfo</CodeStep> que contém o <CodeStep step={5}>componentStack</CodeStep> do erro.
943
943
944
-
You can use the `onRecoverableError`root option to display error dialogs for hydration mismatches:
944
+
Você pode usar a opção da raiz `onRecoverableError`para mostrar diálogos de erro para diferenças de hidratação:
945
945
946
946
<Sandpack>
947
947
@@ -1175,20 +1175,20 @@ function Throw({error}) {
1175
1175
1176
1176
</Sandpack>
1177
1177
1178
-
## Troubleshooting {/*troubleshooting*/}
1178
+
## Solução de problemas {/*troubleshooting*/}
1179
1179
1180
1180
1181
-
### I'm getting an error: "You passed a second argument to root.render" {/*im-getting-an-error-you-passed-a-second-argument-to-root-render*/}
1181
+
### Estou recebendo esse erro: "You passed a second argument to root.render" {/*im-getting-an-error-you-passed-a-second-argument-to-root-render*/}
1182
1182
1183
-
A common mistake is to pass the options for `hydrateRoot`to`root.render(...)`:
1183
+
um erro comum é passar as opções de `hydrateRoot`para`root.render(...)`:
1184
1184
1185
1185
<ConsoleBlock level="error">
1186
1186
1187
1187
Warning: You passed a second argument to root.render(...) but it only accepts one argument.
1188
1188
1189
1189
</ConsoleBlock>
1190
1190
1191
-
To fix, pass the root options to `hydrateRoot(...)`, not`root.render(...)`:
1191
+
Para correção, passe as opções da raiz para `hydrateRoot(...)`, e não para`root.render(...)`:
0 commit comments