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/eslint-plugin-react-hooks/lints/globals.md
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,55 +4,55 @@ title: globals
4
4
5
5
<Intro>
6
6
7
-
Validates against assignment/mutation of globals during render, part of ensuring that [side effects must run outside of render](/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render).
7
+
Valida contra a atribuição/mutação de globais durante a renderização, parte de garantir que [efeitos colaterais devem ser executados fora da renderização](/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render).
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## Detalhes da Regra {/*rule-details*/}
12
12
13
-
Global variables exist outside React's control. When you modify them during render, you break React's assumption that rendering is pure. This can cause components to behave differently in development vs production, break Fast Refresh, and make your app impossible to optimize with features like React Compiler.
13
+
Variáveis globais existem fora do controle do React. Quando você as modifica durante a renderização, você quebra a suposição do React de que a renderização é pura. Isso pode fazer com que os componentes se comportem de maneira diferente em desenvolvimento vs produção, quebrar o Fast Refresh e tornar seu aplicativo impossível de otimizar com recursos como o React Compiler.
14
14
15
-
### Invalid {/*invalid*/}
15
+
### Inválido {/*invalid*/}
16
16
17
-
Examples of incorrect code for this rule:
17
+
Exemplos de código incorreto para esta regra:
18
18
19
19
```js
20
-
// ❌ Global counter
20
+
// ❌ Contador global
21
21
let renderCount =0;
22
22
functionComponent() {
23
-
renderCount++; //Mutating global
24
-
return<div>Count: {renderCount}</div>;
23
+
renderCount++; //Mutando global
24
+
return<div>Contagem: {renderCount}</div>;
25
25
}
26
26
27
-
// ❌ Modifying window properties
27
+
// ❌ Modificando propriedades do window
28
28
functionComponent({userId}) {
29
-
window.currentUser= userId; //Global mutation
30
-
return<div>User: {userId}</div>;
29
+
window.currentUser= userId; //Mutação global
30
+
return<div>Usuário: {userId}</div>;
31
31
}
32
32
33
-
// ❌ Global array push
33
+
// ❌ Push em array global
34
34
constevents= [];
35
35
functionComponent({event}) {
36
-
events.push(event); //Mutating global array
37
-
return<div>Events: {events.length}</div>;
36
+
events.push(event); //Mutando array global
37
+
return<div>Eventos: {events.length}</div>;
38
38
}
39
39
40
-
// ❌ Cache manipulation
40
+
// ❌ Manipulação de cache
41
41
constcache= {};
42
42
functionComponent({id}) {
43
43
if (!cache[id]) {
44
-
cache[id] =fetchData(id); //Modifying cache during render
44
+
cache[id] =fetchData(id); //Modificando cache durante a renderização
0 commit comments