Skip to content

Commit 3cfc80b

Browse files
docs: translate purity.md to Português (Brasil) (#1215)
1 parent 85f0e7f commit 3cfc80b

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

  • src/content/reference/eslint-plugin-react-hooks/lints

src/content/reference/eslint-plugin-react-hooks/lints/purity.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,67 @@ title: purity
44

55
<Intro>
66

7-
Validates that [components/hooks are pure](/reference/rules/components-and-hooks-must-be-pure) by checking that they do not call known-impure functions.
7+
Valida que [componentes/hooks são puros](/reference/rules/components-and-hooks-must-be-pure) verificando se eles não chamam funções conhecidas como impuras.
88

99
</Intro>
1010

11-
## Rule Details {/*rule-details*/}
11+
## Detalhes da Regra {/*rule-details*/}
1212

13-
React components must be pure functions - given the same props, they should always return the same JSX. When components use functions like `Math.random()` or `Date.now()` during render, they produce different output each time, breaking React's assumptions and causing bugs like hydration mismatches, incorrect memoization, and unpredictable behavior.
13+
Componentes React devem ser funções puras - dadas as mesmas props, eles devem sempre retornar o mesmo JSX. Quando componentes usam funções como `Math.random()` ou `Date.now()` durante a renderização, eles produzem saídas diferentes a cada vez, quebrando as suposições do React e causando erros como incompatibilidades de hidratação, memoização incorreta e comportamento imprevisível.
1414

15-
## Common Violations {/*common-violations*/}
15+
## Violações Comuns {/*common-violations*/}
1616

17-
In general, any API that returns a different value for the same inputs violates this rule. Usual examples include:
17+
Em geral, qualquer API que retorna um valor diferente para as mesmas entradas viola esta regra. Exemplos comuns incluem:
1818

1919
- `Math.random()`
2020
- `Date.now()` / `new Date()`
2121
- `crypto.randomUUID()`
2222
- `performance.now()`
2323

24-
### Invalid {/*invalid*/}
24+
### Inválido {/*invalid*/}
2525

26-
Examples of incorrect code for this rule:
26+
Exemplos de código incorreto para esta regra:
2727

2828
```js
29-
// ❌ Math.random() in render
29+
// ❌ Math.random() na renderização
3030
function Component() {
31-
const id = Math.random(); // Different every render
31+
const id = Math.random(); // Diferente a cada renderização
3232
return <div key={id}>Content</div>;
3333
}
3434

35-
// ❌ Date.now() for values
35+
// ❌ Date.now() para valores
3636
function Component() {
37-
const timestamp = Date.now(); // Changes every render
37+
const timestamp = Date.now(); // Muda a cada renderização
3838
return <div>Created at: {timestamp}</div>;
3939
}
4040
```
4141

42-
### Valid {/*valid*/}
42+
### Válido {/*valid*/}
4343

44-
Examples of correct code for this rule:
44+
Exemplos de código correto para esta regra:
4545

4646
```js
47-
//Stable IDs from initial state
47+
// ✅ IDs estáveis a partir do estado inicial
4848
function Component() {
4949
const [id] = useState(() => crypto.randomUUID());
5050
return <div key={id}>Content</div>;
5151
}
5252
```
5353

54-
## Troubleshooting {/*troubleshooting*/}
54+
## Solução de Problemas {/*troubleshooting*/}
5555

56-
### I need to show the current time {/*current-time*/}
56+
### Preciso mostrar a hora atual {/*current-time*/}
5757

58-
Calling `Date.now()` during render makes your component impure:
58+
Chamar `Date.now()` durante a renderização torna seu componente impuro:
5959

6060
```js {expectedErrors: {'react-compiler': [3]}}
61-
//Wrong: Time changes every render
61+
//Errado: A hora muda a cada renderização
6262
function Clock() {
6363
return <div>Current time: {Date.now()}</div>;
6464
}
6565
```
6666

67-
Instead, [move the impure function outside of render](/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent):
67+
Em vez disso, [mova a função impura para fora da renderização](/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent):
6868

6969
```js
7070
function Clock() {

0 commit comments

Comments
 (0)