Skip to content

Commit 2cc4bad

Browse files
docs: translate refs.md to Português (Brasil)
1 parent 1d57663 commit 2cc4bad

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

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

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,83 +4,83 @@ title: refs
44

55
<Intro>
66

7-
Validates correct usage of refs, not reading/writing during render. See the "pitfalls" section in [`useRef()` usage](/reference/react/useRef#usage).
7+
Valida o uso correto de refs, não lendo/escrevendo durante a renderização. Veja a seção "armadilhas" em [`useRef()` usage](/reference/react/useRef#usage).
88

99
</Intro>
1010

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

13-
Refs hold values that aren't used for rendering. Unlike state, changing a ref doesn't trigger a re-render. Reading or writing `ref.current` during render breaks React's expectations. Refs might not be initialized when you try to read them, and their values can be stale or inconsistent.
13+
Refs armazenam valores que não são usados para renderização. Diferente do estado, alterar uma ref não dispara uma nova renderização. Ler ou escrever `ref.current` durante a renderização quebra as expectativas do React. Refs podem não estar inicializadas quando você tenta lê-las, e seus valores podem estar desatualizados ou inconsistentes.
1414

15-
## How It Detects Refs {/*how-it-detects-refs*/}
15+
## Como Detecta Refs {/*how-it-detects-refs*/}
1616

17-
The lint only applies these rules to values it knows are refs. A value is inferred as a ref when the compiler sees any of the following patterns:
17+
A lint aplica estas regras apenas a valores que ela sabe serem refs. Um valor é inferido como ref quando o compilador vê qualquer um dos seguintes padrões:
1818

19-
- Returned from `useRef()` or `React.createRef()`.
19+
- Retornado de `useRef()` ou `React.createRef()`.
2020

2121
```js
2222
const scrollRef = useRef(null);
2323
```
2424

25-
- An identifier named `ref` or ending in `Ref` that reads from or writes to `.current`.
25+
- Um identificador chamado `ref` ou que termina em `Ref` que lê ou escreve em `.current`.
2626

2727
```js
2828
buttonRef.current = node;
2929
```
3030

31-
- Passed through a JSX `ref` prop (for example `<div ref={someRef} />`).
31+
- Passado através de uma prop `ref` JSX (por exemplo `<div ref={someRef} />`).
3232

3333
```jsx
3434
<input ref={inputRef} />
3535
```
3636

37-
Once something is marked as a ref, that inference follows the value through assignments, destructuring, or helper calls. This lets the lint surface violations even when `ref.current` is accessed inside another function that received the ref as an argument.
37+
Uma vez que algo é marcado como ref, essa inferência segue o valor através de atribuições, desestruturação ou chamadas de funções auxiliares. Isso permite que a lint aponte violações mesmo quando `ref.current` é acessado dentro de outra função que recebeu a ref como argumento.
3838

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

41-
- Reading `ref.current` during render
42-
- Updating `refs` during render
43-
- Using `refs` for values that should be state
41+
- Lendo `ref.current` durante a renderização
42+
- Atualizando `refs` durante a renderização
43+
- Usando `refs` para valores que deveriam ser estado
4444

45-
### Invalid {/*invalid*/}
45+
### Inválido {/*invalid*/}
4646

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

4949
```js
50-
//Reading ref during render
50+
//Lendo ref durante a renderização
5151
function Component() {
5252
const ref = useRef(0);
53-
const value = ref.current; // Don't read during render
53+
const value = ref.current; // Não leia durante a renderização
5454
return <div>{value}</div>;
5555
}
5656

57-
//Modifying ref during render
57+
//Modificando ref durante a renderização
5858
function Component({value}) {
5959
const ref = useRef(null);
60-
ref.current = value; // Don't modify during render
60+
ref.current = value; // Não modifique durante a renderização
6161
return <div />;
6262
}
6363
```
6464

65-
### Valid {/*valid*/}
65+
### Válido {/*valid*/}
6666

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

6969
```js
70-
//Read ref in effects/handlers
70+
//Leia ref em efeitos/manipuladores
7171
function Component() {
7272
const ref = useRef(null);
7373

7474
useEffect(() => {
7575
if (ref.current) {
76-
console.log(ref.current.offsetWidth); // OK in effect
76+
console.log(ref.current.offsetWidth); // OK no efeito
7777
}
7878
});
7979

8080
return <div ref={ref} />;
8181
}
8282

83-
// ✅ Use state for UI values
83+
// ✅ Use estado para valores de UI
8484
function Component() {
8585
const [count, setCount] = useState(0);
8686

@@ -91,25 +91,25 @@ function Component() {
9191
);
9292
}
9393

94-
//Lazy initialization of ref value
94+
//Inicialização preguiçosa do valor da ref
9595
function Component() {
9696
const ref = useRef(null);
9797

98-
// Initialize only once on first use
98+
// Inicializa apenas uma vez no primeiro uso
9999
if (ref.current === null) {
100-
ref.current = expensiveComputation(); // OK - lazy initialization
100+
ref.current = expensiveComputation(); // OK - inicialização preguiçosa
101101
}
102102

103103
const handleClick = () => {
104-
console.log(ref.current); // Use the initialized value
104+
console.log(ref.current); // Use o valor inicializado
105105
};
106106

107107
return <button onClick={handleClick}>Click</button>;
108108
}
109109
```
110110

111-
## Troubleshooting {/*troubleshooting*/}
111+
## Solução de Problemas {/*troubleshooting*/}
112112

113-
### The lint flagged my plain object with `.current` {/*plain-object-current*/}
113+
### A lint sinalizou meu objeto simples com `.current` {/*plain-object-current*/}
114114

115-
The name heuristic intentionally treats `ref.current` and `fooRef.current` as real refs. If you're modeling a custom container object, pick a different name (for example, `box`) or move the mutable value into state. Renaming avoids the lint because the compiler stops inferring it as a ref.
115+
A heurística de nome intencionalmente trata `ref.current` e `fooRef.current` como refs reais. Se você está modelando um objeto contêiner personalizado, escolha um nome diferente (por exemplo, `box`) ou mova o valor mutável para o estado. Renomear evita a lint porque o compilador para de inferi-lo como uma ref.

0 commit comments

Comments
 (0)