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/preinit.md
+33-33
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@ title: preinit
4
4
5
5
<Note>
6
6
7
-
[React-based frameworks](/learn/start-a-new-react-project)frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
7
+
[Frameworks baseados em React](/learn/start-a-new-react-project)frequentemente tratam o carregamento de recursos para você, então talvez você não precise chamar esta API sozinho. Consulte a documentação do seu framework para mais detalhes.
8
8
9
9
</Note>
10
10
11
11
<Intro>
12
12
13
-
`preinit`lets you eagerly fetch and evaluate a stylesheet or external script.
13
+
`preinit`permite que você busque e avalie ansiosamente uma folha de estilo ou script externo.
To preinit a script or stylesheet, call the `preinit`function from`react-dom`.
29
+
Para pré-inicializar um script ou folha de estilo, chame a função `preinit`de`react-dom`.
30
30
31
31
```js
32
32
import { preinit } from'react-dom';
@@ -38,42 +38,42 @@ function AppRoot() {
38
38
39
39
```
40
40
41
-
[See more examples below.](#usage)
41
+
[Veja mais exemplos abaixo.](#usage)
42
42
43
-
The `preinit`function provides the browser with a hint that it should start downloading and executing the given resource, which can save time. Scripts that you`preinit`are executed when they finish downloading. Stylesheets that you preinit are inserted into the document, which causes them to go into effect right away.
43
+
A função `preinit`fornece ao navegador uma dica de que ele deve começar a baixar e executar o recurso fornecido, o que pode economizar tempo. Scripts que você`preinit`são executados quando terminam o download. Folhas de estilo que você pré-inicializa são inseridas no documento, o que faz com que entrem em vigor imediatamente.
44
44
45
-
#### Parameters {/*parameters*/}
45
+
#### Parâmetros {/*parameters*/}
46
46
47
-
*`href`: a string. The URL of the resource you want to download and execute.
48
-
*`options`: an object. It contains the following properties:
49
-
*`as`: a required string. The type of resource. Its possible values are`script`and`style`.
50
-
*`precedence`: a string. Required with stylesheets. Says where to insert the stylesheet relative to others. Stylesheets with higher precedence can override those with lower precedence. The possible values are`reset`, `low`, `medium`, `high`.
51
-
*`crossOrigin`: a string. The [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)to use. Its possible values are`anonymous`and`use-credentials`. It is required when `as`is set to`"fetch"`.
52
-
*`integrity`: a string. A cryptographic hash of the resource, to [verify its authenticity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
53
-
*`nonce`: a string. A cryptographic [nonce to allow the resource](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce)when using a strict Content Security Policy.
54
-
*`fetchPriority`: a string. Suggests a relative priority for fetching the resource. The possible values are`auto` (the default), `high`, and`low`.
47
+
*`href`: uma string. A URL do recurso que você deseja baixar e executar.
48
+
*`options`: um objeto. Ele contém as seguintes propriedades:
49
+
*`as`: uma string obrigatória. O tipo de recurso. Seus valores possíveis são`script`e`style`.
50
+
*`precedence`: uma string. Obrigatório com folhas de estilo. Diz onde inserir a folha de estilo em relação a outras. Folhas de estilo com maior precedência podem substituir aquelas com menor precedência. Os valores possíveis são`reset`, `low`, `medium`, `high`.
51
+
*`crossOrigin`: uma string. A [política CORS](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)a ser usada. Seus valores possíveis são`anonymous`e`use-credentials`. É necessário quando `as`é definido como`"fetch"`.
52
+
*`integrity`: uma string. Um hash criptográfico do recurso, para [verificar sua autenticidade](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
53
+
*`nonce`: uma string. Um [nonce](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce)criptográfico para permitir o recurso ao usar uma Política de Segurança de Conteúdo estrita.
54
+
*`fetchPriority`: uma string. Sugere uma prioridade relativa para buscar o recurso. Os valores possíveis são`auto` (o padrão), `high` e`low`.
55
55
56
-
#### Returns {/*returns*/}
56
+
#### Retorna {/*returns*/}
57
57
58
-
`preinit`returns nothing.
58
+
`preinit`não retorna nada.
59
59
60
-
#### Caveats {/*caveats*/}
60
+
#### Ressalvas {/*caveats*/}
61
61
62
-
*Multiple calls to`preinit`with the same`href`have the same effect as a single call.
63
-
*In the browser, you can call`preinit`in any situation: while rendering a component, in an Effect, in an event handler, and so on.
64
-
*In server-side rendering or when rendering Server Components, `preinit`only has an effect if you call it while rendering a component or in an async context originating from rendering a component. Any other calls will be ignored.
62
+
*Várias chamadas para`preinit`com o mesmo`href`têm o mesmo efeito de uma única chamada.
63
+
*No navegador, você pode chamar`preinit`em qualquer situação: ao renderizar um componente, em um Effect, em um manipulador de eventos e assim por diante.
64
+
*Na renderização do lado do servidor ou ao renderizar Componentes do Servidor, `preinit`só tem efeito se você o chamar ao renderizar um componente ou em um contexto assíncrono originado da renderização de um componente. Quaisquer outras chamadas serão ignoradas.
65
65
66
66
---
67
67
68
-
## Usage {/*usage*/}
68
+
## Uso {/*usage*/}
69
69
70
-
### Preiniting when rendering {/*preiniting-when-rendering*/}
70
+
### Pré-inicializando ao renderizar {/*preiniting-when-rendering*/}
71
71
72
-
Call`preinit`when rendering a component if you know that it or its children will use a specific resource, and you're OK with the resource being evaluated and thereby taking effect immediately upon being downloaded.
72
+
Chame`preinit`ao renderizar um componente se você souber que ele ou seus filhos usarão um recurso específico e estiver tudo bem com o recurso sendo avaliado e, portanto, entrando em vigor imediatamente após o download.
73
73
74
-
<RecipestitleText="Examples of preiniting">
74
+
<RecipestitleText="Exemplos de pré-inicialização">
75
75
76
-
#### Preiniting an external script {/*preiniting-an-external-script*/}
76
+
#### Pré-inicializando um script externo {/*preiniting-an-external-script*/}
77
77
78
78
```js
79
79
import { preinit } from'react-dom';
@@ -84,11 +84,11 @@ function AppRoot() {
84
84
}
85
85
```
86
86
87
-
If you want the browser to download the script but not to execute it right away, use [`preload`](/reference/react-dom/preload)instead. If you want to load an ESM module, use [`preinitModule`](/reference/react-dom/preinitModule).
87
+
Se você quiser que o navegador baixe o script, mas não o execute imediatamente, use [`preload`](/reference/react-dom/preload)em vez disso. Se você quiser carregar um módulo ESM, use [`preinitModule`](/reference/react-dom/preinitModule).
88
88
89
89
<Solution />
90
90
91
-
#### Preiniting a stylesheet {/*preiniting-a-stylesheet*/}
91
+
#### Pré-inicializando uma folha de estilo {/*preiniting-a-stylesheet*/}
92
92
93
93
```js
94
94
import { preinit } from'react-dom';
@@ -99,17 +99,17 @@ function AppRoot() {
99
99
}
100
100
```
101
101
102
-
The `precedence` option, which is required, lets you control the order of stylesheets within the document. Stylesheets with higher precedence can overrule those with lower precedence.
102
+
A opção `precedence`, que é obrigatória, permite que você controle a ordem das folhas de estilo dentro do documento. Folhas de estilo com maior precedência podem anular as com menor precedência.
103
103
104
-
If you want to download the stylesheet but not to insert it into the document right away, use [`preload`](/reference/react-dom/preload)instead.
104
+
Se você quiser baixar a folha de estilo, mas não inseri-la no documento imediatamente, use [`preload`](/reference/react-dom/preload)em vez disso.
105
105
106
106
<Solution />
107
107
108
108
</Recipes>
109
109
110
-
### Preiniting in an event handler {/*preiniting-in-an-event-handler*/}
110
+
### Pré-inicializando em um manipulador de eventos {/*preiniting-in-an-event-handler*/}
111
111
112
-
Call`preinit`in an event handler before transitioning to a page or state where external resources will be needed. This gets the process started earlier than if you call it during the rendering of the new page or state.
112
+
Chame`preinit`em um manipulador de eventos antes de fazer a transição para uma página ou estado onde recursos externos serão necessários. Isso inicia o processo mais cedo do que se você o chamasse durante a renderização da nova página ou estado.
0 commit comments