Skip to content

Commit d54fd54

Browse files
docs: translate immutability.md to Português (Brasil) (#1214)
Co-authored-by: translate-react-bot[bot] <251169733+translate-react-bot[bot]@users.noreply.github.com>
1 parent f0d9c1c commit d54fd54

1 file changed

Lines changed: 33 additions & 33 deletions

File tree

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,85 @@ title: immutability
44

55
<Intro>
66

7-
Validates against mutating props, state, and other values that [are immutable](/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable).
7+
Valida contra a mutação de props, estado e outros valores que [são imutáveis](/reference/rules/components-and-hooks-must-be-pure#props-and-state-are-immutable).
88

99
</Intro>
1010

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

13-
A component’s props and state are immutable snapshots. Never mutate them directly. Instead, pass new props down, and use the setter function from `useState`.
13+
As props e o estado de um componente são instantâneos imutáveis. Nunca os modifique diretamente. Em vez disso, passe novas props adiante e use a função de atualização do `useState`.
1414

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

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

1919
```js
20-
//Array push mutation
20+
//Mutação de push em array
2121
function Component() {
2222
const [items, setItems] = useState([1, 2, 3]);
2323

2424
const addItem = () => {
25-
items.push(4); // Mutating!
26-
setItems(items); // Same reference, no re-render
25+
items.push(4); // Mutando!
26+
setItems(items); // Mesma referência, sem re-renderização
2727
};
2828
}
2929

30-
//Object property assignment
30+
//Atribuição de propriedade de objeto
3131
function Component() {
3232
const [user, setUser] = useState({name: 'Alice'});
3333

3434
const updateName = () => {
35-
user.name = 'Bob'; // Mutating!
36-
setUser(user); // Same reference
35+
user.name = 'Bob'; // Mutando!
36+
setUser(user); // Mesma referência
3737
};
3838
}
3939

40-
//Sort without spreading
40+
//Ordenação sem espalhamento (spread)
4141
function Component() {
4242
const [items, setItems] = useState([3, 1, 2]);
4343

4444
const sortItems = () => {
45-
setItems(items.sort()); // sort mutates!
45+
setItems(items.sort()); // sort muta!
4646
};
4747
}
4848
```
4949

50-
### Valid {/*valid*/}
50+
### Válido {/*valid*/}
5151

5252
```js
53-
//Create new array
53+
//Cria novo array
5454
function Component() {
5555
const [items, setItems] = useState([1, 2, 3]);
5656

5757
const addItem = () => {
58-
setItems([...items, 4]); // New array
58+
setItems([...items, 4]); // Novo array
5959
};
6060
}
6161

62-
//Create new object
62+
//Cria novo objeto
6363
function Component() {
6464
const [user, setUser] = useState({name: 'Alice'});
6565

6666
const updateName = () => {
67-
setUser({...user, name: 'Bob'}); // New object
67+
setUser({...user, name: 'Bob'}); // Novo objeto
6868
};
6969
}
7070
```
7171

72-
## Troubleshooting {/*troubleshooting*/}
72+
## Solução de Problemas {/*troubleshooting*/}
7373

74-
### I need to add items to an array {/*add-items-array*/}
74+
### Preciso adicionar itens a um array {/*add-items-array*/}
7575

76-
Mutating arrays with methods like `push()` won't trigger re-renders:
76+
Mutar arrays com métodos como `push()` não aciona re-renderizações:
7777

7878
```js
79-
//Wrong: Mutating the array
79+
//Errado: Mutando o array
8080
function TodoList() {
8181
const [todos, setTodos] = useState([]);
8282

8383
const addTodo = (id, text) => {
8484
todos.push({id, text});
85-
setTodos(todos); // Same array reference!
85+
setTodos(todos); // Mesma referência de array!
8686
};
8787

8888
return (
@@ -93,16 +93,16 @@ function TodoList() {
9393
}
9494
```
9595

96-
Create a new array instead:
96+
Crie um novo array em vez disso:
9797

9898
```js
99-
//Better: Create a new array
99+
//Melhor: Cria um novo array
100100
function TodoList() {
101101
const [todos, setTodos] = useState([]);
102102

103103
const addTodo = (id, text) => {
104104
setTodos([...todos, {id, text}]);
105-
// Or: setTodos(todos => [...todos, {id: Date.now(), text}])
105+
// Ou: setTodos(todos => [...todos, {id: Date.now(), text}])
106106
};
107107

108108
return (
@@ -113,12 +113,12 @@ function TodoList() {
113113
}
114114
```
115115

116-
### I need to update nested objects {/*update-nested-objects*/}
116+
### Preciso atualizar objetos aninhados {/*update-nested-objects*/}
117117

118-
Mutating nested properties doesn't trigger re-renders:
118+
Mutar propriedades aninhadas não aciona re-renderizações:
119119

120120
```js
121-
//Wrong: Mutating nested object
121+
//Errado: Mutando objeto aninhado
122122
function UserProfile() {
123123
const [user, setUser] = useState({
124124
name: 'Alice',
@@ -129,16 +129,16 @@ function UserProfile() {
129129
});
130130

131131
const toggleTheme = () => {
132-
user.settings.theme = 'dark'; // Mutation!
133-
setUser(user); // Same object reference
132+
user.settings.theme = 'dark'; // Mutação!
133+
setUser(user); // Mesma referência de objeto
134134
};
135135
}
136136
```
137137

138-
Spread at each level that needs updating:
138+
Use o espalhamento (spread) em cada nível que precisa ser atualizado:
139139

140140
```js
141-
//Better: Create new objects at each level
141+
//Melhor: Cria novos objetos em cada nível
142142
function UserProfile() {
143143
const [user, setUser] = useState({
144144
name: 'Alice',

0 commit comments

Comments
 (0)