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/unsupported-syntax.md
+28-28Lines changed: 28 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,99 +4,99 @@ title: unsupported-syntax
4
4
5
5
<Intro>
6
6
7
-
Validates against syntax that React Compiler does not support. If you need to, you can still use this syntax outside of React, such as in a standalone utility function.
7
+
Valida contra sintaxes que o React Compiler não suporta. Se necessário, você ainda pode usar essa sintaxe fora do React, como em uma função utilitária independente.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## Detalhes da Regra {/*rule-details*/}
12
12
13
-
React Compiler needs to statically analyze your code to apply optimizations. Features like`eval`and`with`make it impossible to statically understand what the code does at compile time, so the compiler can't optimize components that use them.
13
+
O React Compiler precisa analisar estaticamente seu código para aplicar otimizações. Recursos como`eval`e`with`tornam impossível entender estaticamente o que o código faz em tempo de compilação, portanto, o compilador não pode otimizar componentes que os utilizam.
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
-
// ❌ Using eval in component
20
+
// ❌ Usando eval em um componente
21
21
functionComponent({ code }) {
22
-
constresult=eval(code); //Can't be analyzed
22
+
constresult=eval(code); //Não pode ser analisado
23
23
return<div>{result}</div>;
24
24
}
25
25
26
-
// ❌ Using with statement
26
+
// ❌ Usando a declaração with
27
27
functionComponent() {
28
-
with (Math) { //Changes scope dynamically
28
+
with (Math) { //Altera o escopo dinamicamente
29
29
return<div>{sin(PI/2)}</div>;
30
30
}
31
31
}
32
32
33
-
// ❌ Dynamic property access with eval
33
+
// ❌ Acesso dinâmico a propriedades com eval
34
34
functionComponent({propName}) {
35
35
constvalue=eval(`props.${propName}`);
36
36
return<div>{value}</div>;
37
37
}
38
38
```
39
39
40
-
### Valid {/*valid*/}
40
+
### Válido {/*valid*/}
41
41
42
-
Examples of correct code for this rule:
42
+
Exemplos de código correto para esta regra:
43
43
44
44
```js
45
-
// ✅ Use normal property access
45
+
// ✅ Usa acesso normal a propriedades
46
46
functionComponent({propName, props}) {
47
-
constvalue= props[propName]; //Analyzable
47
+
constvalue= props[propName]; //Analisável
48
48
return<div>{value}</div>;
49
49
}
50
50
51
-
// ✅ Use standard Math methods
51
+
// ✅ Usa métodos padrão do Math
52
52
functionComponent() {
53
53
return<div>{Math.sin(Math.PI/2)}</div>;
54
54
}
55
55
```
56
56
57
-
## Troubleshooting {/*troubleshooting*/}
57
+
## Solução de Problemas {/*troubleshooting*/}
58
58
59
-
### I need to evaluate dynamic code {/*evaluate-dynamic-code*/}
Você pode precisar avaliar código fornecido pelo usuário:
62
62
63
63
```js {expectedErrors: {'react-compiler': [3]}}
64
-
// ❌ Wrong: eval in component
64
+
// ❌ Errado: eval em um componente
65
65
functionCalculator({expression}) {
66
-
constresult=eval(expression); //Unsafe and unoptimizable
66
+
constresult=eval(expression); //Inseguro e não otimizável
67
67
return<div>Result: {result}</div>;
68
68
}
69
69
```
70
70
71
-
Use a safe expression parser instead:
71
+
Use um analisador de expressões seguro em vez disso:
72
72
73
73
```js
74
-
// ✅ Better: Use a safe parser
75
-
import {evaluate} from'mathjs'; //or similar library
74
+
// ✅ Melhor: Usa um analisador seguro
75
+
import {evaluate} from'mathjs'; //ou biblioteca similar
76
76
77
77
functionCalculator({expression}) {
78
78
const [result, setResult] =useState(null);
79
79
80
80
constcalculate= () => {
81
81
try {
82
-
//Safe mathematical expression evaluation
82
+
//Avaliação segura de expressões matemáticas
83
83
setResult(evaluate(expression));
84
84
} catch (error) {
85
-
setResult('Invalid expression');
85
+
setResult('Expressão inválida');
86
86
}
87
87
};
88
88
89
89
return (
90
90
<div>
91
-
<button onClick={calculate}>Calculate</button>
92
-
{result &&<div>Result: {result}</div>}
91
+
<button onClick={calculate}>Calcular</button>
92
+
{result &&<div>Resultado: {result}</div>}
93
93
</div>
94
94
);
95
95
}
96
96
```
97
97
98
98
<Note>
99
99
100
-
Never use `eval`with user input - it's a security risk. Use dedicated parsing libraries for specific use cases like mathematical expressions, JSON parsing, or template evaluation.
100
+
Nunca use `eval`com entrada do usuário - é um risco de segurança. Use bibliotecas de análise dedicadas para casos de uso específicos, como expressões matemáticas, análise de JSON ou avaliação de templates.
0 commit comments