Skip to content

Commit ff0ced6

Browse files
docs: translate set-state-in-render.md to Português (Brasil)
1 parent 1d57663 commit ff0ced6

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

src/content/reference/eslint-plugin-react-hooks/lints/set-state-in-render.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ title: set-state-in-render
44

55
<Intro>
66

7-
Validates against unconditionally setting state during render, which can trigger additional renders and potential infinite render loops.
7+
Valida contra a definição incondicional de estado durante a renderização, o que pode acionar renderizações adicionais e potenciais loops de renderização infinitos.
88

99
</Intro>
1010

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

13-
Calling `setState` during render unconditionally triggers another render before the current one finishes. This creates an infinite loop that crashes your app.
13+
Chamar `setState` durante a renderização aciona incondicionalmente outra renderização antes que a atual termine. Isso cria um loop infinito que trava seu aplicativo.
1414

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

17-
### Invalid {/*invalid*/}
17+
### Inválido {/*invalid*/}
1818

1919
```js {expectedErrors: {'react-compiler': [4]}}
20-
//Unconditional setState directly in render
20+
// ❌ setState incondicional diretamente na renderização
2121
function Component({value}) {
2222
const [count, setCount] = useState(0);
23-
setCount(value); // Infinite loop!
23+
setCount(value); // Loop infinito!
2424
return <div>{count}</div>;
2525
}
2626
```
2727

28-
### Valid {/*valid*/}
28+
### Válido {/*valid*/}
2929

3030
```js
31-
//Derive during render
31+
//Derivar durante a renderização
3232
function Component({items}) {
33-
const sorted = [...items].sort(); // Just calculate it in render
33+
const sorted = [...items].sort(); // Apenas calcule na renderização
3434
return <ul>{sorted.map(/*...*/)}</ul>;
3535
}
3636

37-
//Set state in event handler
37+
//Definir estado no manipulador de eventos
3838
function Component() {
3939
const [count, setCount] = useState(0);
4040
return (
@@ -44,35 +44,35 @@ function Component() {
4444
);
4545
}
4646

47-
//Derive from props instead of setting state
47+
//Derivar de props em vez de definir estado
4848
function Component({user}) {
4949
const name = user?.name || '';
5050
const email = user?.email || '';
5151
return <div>{name}</div>;
5252
}
5353

54-
//Conditionally derive state from props and state from previous renders
54+
//Derivar condicionalmente estado de props e estado de renderizações anteriores
5555
function Component({ items }) {
5656
const [isReverse, setIsReverse] = useState(false);
5757
const [selection, setSelection] = useState(null);
5858

5959
const [prevItems, setPrevItems] = useState(items);
60-
if (items !== prevItems) { // This condition makes it valid
60+
if (items !== prevItems) { // Esta condição a torna válida
6161
setPrevItems(items);
6262
setSelection(null);
6363
}
6464
// ...
6565
}
6666
```
6767
68-
## Troubleshooting {/*troubleshooting*/}
68+
## Solução de Problemas {/*troubleshooting*/}
6969
70-
### I want to sync state to a prop {/*clamp-state-to-prop*/}
70+
### Quero sincronizar o estado com uma prop {/*clamp-state-to-prop*/}
7171
72-
A common problem is trying to "fix" state after it renders. Suppose you want to keep a counter from exceeding a `max` prop:
72+
Um problema comum é tentar "corrigir" o estado após a renderização. Suponha que você queira impedir que um contador exceda uma prop `max`:
7373
7474
```js
75-
//Wrong: clamps during render
75+
//Errado: limita durante a renderização
7676
function Counter({max}) {
7777
const [count, setCount] = useState(0);
7878

@@ -88,12 +88,12 @@ function Counter({max}) {
8888
}
8989
```
9090
91-
As soon as `count` exceeds `max`, an infinite loop is triggered.
91+
Assim que `count` exceder `max`, um loop infinito é acionado.
9292
93-
Instead, it's often better to move this logic to the event (the place where the state is first set). For example, you can enforce the maximum at the moment you update state:
93+
Em vez disso, geralmente é melhor mover essa lógica para o evento (o local onde o estado é definido pela primeira vez). Por exemplo, você pode impor o máximo no momento em que atualiza o estado:
9494
9595
```js
96-
//Clamp when updating
96+
//Limita ao atualizar
9797
function Counter({max}) {
9898
const [count, setCount] = useState(0);
9999

@@ -105,6 +105,6 @@ function Counter({max}) {
105105
}
106106
```
107107
108-
Now the setter only runs in response to the click, React finishes the render normally, and `count` never crosses `max`.
108+
Agora, o setter só é executado em resposta ao clique, o React termina a renderização normalmente e `count` nunca ultrapassa `max`.
109109
110-
In rare cases, you may need to adjust state based on information from previous renders. For those, follow [this pattern](https://react.dev/reference/react/useState#storing-information-from-previous-renders) of setting state conditionally.
110+
Em casos raros, você pode precisar ajustar o estado com base em informações de renderizações anteriores. Para esses casos, siga [este padrão](https://react.dev/reference/react/useState#storing-information-from-previous-renders) de definir o estado condicionalmente.

0 commit comments

Comments
 (0)