Skip to content

Commit 69af38c

Browse files
WendellAdrielfjoshuajr
authored andcommitted
Lists and Keys page translation (#7)
* translated Lists and Keys page * translated nav title for the Lists and Keys section * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Update to fix/improve the translation Co-Authored-By: WendellAdriel <[email protected]> * Fixed and improved the translation, following the suggestions on the PR * Update content/docs/lists-and-keys.md Co-Authored-By: WendellAdriel <[email protected]> * Update lists-and-keys.md * Update lists-and-keys.md
1 parent 5a12e0f commit 69af38c

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

content/docs/lists-and-keys.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
---
22
id: lists-and-keys
3-
title: Lists and Keys
3+
title: Listas e Chaves
44
permalink: docs/lists-and-keys.html
55
prev: conditional-rendering.html
66
next: forms.html
77
---
88

9-
First, let's review how you transform lists in JavaScript.
9+
Primeiro, vamos rever como transformamos listas em JavaScript.
1010

11-
Given the code below, we use the [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) function to take an array of `numbers` and double their values. We assign the new array returned by `map()` to the variable `doubled` and log it:
11+
Dado o código abaixo, nós usamos a função [`map()`](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/map) para receber um array de `números` e dobrar o valor de cada um deles. Atribuímos o novo array retornado pela função `map()` para a variável `doubled` e imprime no console:
1212

1313
```javascript{2}
1414
const numbers = [1, 2, 3, 4, 5];
1515
const doubled = numbers.map((number) => number * 2);
1616
console.log(doubled);
1717
```
1818

19-
This code logs `[2, 4, 6, 8, 10]` to the console.
19+
Esse código imprime `[2, 4, 6, 8, 10]` no console.
2020

21-
In React, transforming arrays into lists of [elements](/docs/rendering-elements.html) is nearly identical.
21+
No React, transformar arrays em listas de [elementos](/docs/rendering-elements.html) é praticamente idêntico a isso.
2222

23-
### Rendering Multiple Components {#rendering-multiple-components}
23+
### Renderizando Múltiplos Componentes {#renderizando-multiplos-componentes}
2424

25-
You can build collections of elements and [include them in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) using curly braces `{}`.
25+
Você pode criar coleções de elementos e [adicioná-los no JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) usando chaves `{}`.
2626

27-
Below, we loop through the `numbers` array using the JavaScript [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) function. We return a `<li>` element for each item. Finally, we assign the resulting array of elements to `listItems`:
27+
Abaixo, iteramos pelo array `numbers` usando a função [`map()`](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/map) do JavaScript. Retornamos um elemento `<li>` para cada item. Finalmente, atribuímos o array de elementos resultante para `listItems`:
2828

2929
```javascript{2-4}
3030
const numbers = [1, 2, 3, 4, 5];
@@ -33,7 +33,7 @@ const listItems = numbers.map((number) =>
3333
);
3434
```
3535

36-
We include the entire `listItems` array inside a `<ul>` element, and [render it to the DOM](/docs/rendering-elements.html#rendering-an-element-into-the-dom):
36+
Adicionamos todo o array `listItems` dentro de um elemento `<ul>` e [renderizamos ele no DOM](/docs/rendering-elements.html#rendering-an-element-into-the-dom):
3737

3838
```javascript{2}
3939
ReactDOM.render(
@@ -42,15 +42,15 @@ ReactDOM.render(
4242
);
4343
```
4444

45-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
45+
[**Experimente no CodePen**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
4646

47-
This code displays a bullet list of numbers between 1 and 5.
47+
Esse código mostra uma lista não ordenada de números entre 1 e 5.
4848

49-
### Basic List Component {#basic-list-component}
49+
### Componente de Lista Básico {#componente-de-lista-basico}
5050

51-
Usually you would render lists inside a [component](/docs/components-and-props.html).
51+
Geralmente você irá renderizar listas dentro de um [componente](/docs/components-and-props.html).
5252

53-
We can refactor the previous example into a component that accepts an array of `numbers` and outputs an unordered list of elements.
53+
Podemos refatorar o exemplo anterior em um componente que aceita um array de `números` e retorna uma lista não ordenada de elementos.
5454

5555
```javascript{3-5,7,13}
5656
function NumberList(props) {
@@ -70,9 +70,9 @@ ReactDOM.render(
7070
);
7171
```
7272

73-
When you run this code, you'll be given a warning that a key should be provided for list items. A "key" is a special string attribute you need to include when creating lists of elements. We'll discuss why it's important in the next section.
73+
Ao executar esse código, você receberá um aviso que uma chave deve ser definida para os itens da lista. `key` é um atributo string especial que você precisa definir ao criar listas de elementos. Iremos analisar os motivos pelos quais isso é importante na próxima seção.
7474

75-
Let's assign a `key` to our list items inside `numbers.map()` and fix the missing key issue.
75+
Vamos atribuir uma `key` aos itens da nossa lista dentro de `numbers.map()` e resolver o valor da chave que está em falta.
7676

7777
```javascript{4}
7878
function NumberList(props) {
@@ -94,11 +94,11 @@ ReactDOM.render(
9494
);
9595
```
9696

97-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
97+
[**Experimente no CodePen**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
9898

99-
## Keys {#keys}
99+
## Chaves {#chaves}
100100

101-
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity:
101+
As chaves ajudam o React a identificar quais itens sofreram alterações, foram adicionados ou removidos. As chaves devem ser atribuídas aos elementos dentro do array para dar uma identidade estável aos elementos:
102102

103103
```js{3}
104104
const numbers = [1, 2, 3, 4, 5];
@@ -109,7 +109,7 @@ const listItems = numbers.map((number) =>
109109
);
110110
```
111111

112-
The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:
112+
A melhor forma de escolher uma chave é usar uma string que identifica unicamente um item da lista dentre os demais. Na maioria das vezes você usaria IDs de seus dados como chave:
113113

114114
```js{2}
115115
const todoItems = todos.map((todo) =>
@@ -119,34 +119,34 @@ const todoItems = todos.map((todo) =>
119119
);
120120
```
121121

122-
When you don't have stable IDs for rendered items, you may use the item index as a key as a last resort:
122+
Quando você não possui nenhum ID estável para os itens renderizados, você pode usar o índice do item como chave em último recurso:
123123

124124
```js{2,3}
125125
const todoItems = todos.map((todo, index) =>
126-
// Only do this if items have no stable IDs
126+
// Apenas faça isso caso os itens não possuam IDs estáveis
127127
<li key={index}>
128128
{todo.text}
129129
</li>
130130
);
131131
```
132132

133-
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an [in-depth explanation on the negative impacts of using an index as a key](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). If you choose not to assign an explicit key to list items then React will default to using indexes as keys.
133+
Não recomendamos o uso de índices para chave se a ordem dos itens pode ser alterada. Isso pode impactar de forma negativa o desempenho e poderá causar problemas com o estado do componente. Leia o artigo escrito por Robin Pokorny para [uma explicação aprofundada nos impactos negativos de se usar um índice como chave](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). Se você não atribuir uma chave de forma explícita para os itens de uma lista, então o React irá utilizar os índices como chave por padrão.
134134

135-
Here is an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children) if you're interested in learning more.
135+
Aqui você poderá ver [uma explicação aprofundada sobre o porquê o uso das chaves é necessário](/docs/reconciliation.html#recursing-on-children) caso você esteja interessado em aprender mais sobre isso.
136136

137-
### Extracting Components with Keys {#extracting-components-with-keys}
137+
### Extraindo Componentes com Chaves {#extraindo-componentes-com-chaves}
138138

139-
Keys only make sense in the context of the surrounding array.
139+
As chaves apenas fazem sentido no contexto do array que está encapsulando os itens.
140140

141-
For example, if you [extract](/docs/components-and-props.html#extracting-components) a `ListItem` component, you should keep the key on the `<ListItem />` elements in the array rather than on the `<li>` element in the `ListItem` itself.
141+
Por exemplo, se você [extrai](/docs/components-and-props.html#extracting-components) um componente `ListItem`, você deve deixar a chave nos elementos `<ListItem />` ao invés de deixar no elemento `<li>` dentro de `ListItem`.
142142

143-
**Example: Incorrect Key Usage**
143+
**Exemplo: Uso Incorreto de Chaves**
144144

145145
```javascript{4,5,14,15}
146146
function ListItem(props) {
147147
const value = props.value;
148148
return (
149-
// Wrong! There is no need to specify the key here:
149+
// Errado! Não há necessidade de definir a chave aqui:
150150
<li key={value.toString()}>
151151
{value}
152152
</li>
@@ -156,7 +156,7 @@ function ListItem(props) {
156156
function NumberList(props) {
157157
const numbers = props.numbers;
158158
const listItems = numbers.map((number) =>
159-
// Wrong! The key should have been specified here:
159+
// Errado! A chave deveria ser definida aqui:
160160
<ListItem value={number} />
161161
);
162162
return (
@@ -173,18 +173,18 @@ ReactDOM.render(
173173
);
174174
```
175175

176-
**Example: Correct Key Usage**
176+
**Exemplo: Uso Correto de Chaves**
177177

178178
```javascript{2,3,9,10}
179179
function ListItem(props) {
180-
// Correct! There is no need to specify the key here:
180+
// Correto! Não há necessidade de definir a chave aqui:
181181
return <li>{props.value}</li>;
182182
}
183183
184184
function NumberList(props) {
185185
const numbers = props.numbers;
186186
const listItems = numbers.map((number) =>
187-
// Correct! Key should be specified inside the array.
187+
// Correto! A chave deve ser definida dentro do array.
188188
<ListItem key={number.toString()}
189189
value={number} />
190190
);
@@ -202,13 +202,13 @@ ReactDOM.render(
202202
);
203203
```
204204

205-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
205+
[**Experimente no CodePen**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
206206

207-
A good rule of thumb is that elements inside the `map()` call need keys.
207+
Por via de regra, os elementos dentro de uma função `map()` devem especificar chaves.
208208

209-
### Keys Must Only Be Unique Among Siblings {#keys-must-only-be-unique-among-siblings}
209+
### Chaves devem ser Únicas apenas entre Elementos Irmãos {#chaves-devem-ser-unicas-apenas-entre-elementos-irmaos}
210210

211-
Keys used within arrays should be unique among their siblings. However they don't need to be globally unique. We can use the same keys when we produce two different arrays:
211+
Chaves usadas nos arrays devem ser únicas entre seus elementos irmãos. Contudo elas não precisam ser únicas globalmente. Podemos usar as mesmas chaves ao criar dois arrays diferentes:
212212

213213
```js{2,5,11,12,19,21}
214214
function Blog(props) {
@@ -246,9 +246,9 @@ ReactDOM.render(
246246
);
247247
```
248248

249-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
249+
[**Experimente no CodePen**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
250250

251-
Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name:
251+
As chaves servem como uma dica para o React. Mas elas não são passadas para os componentes. Se você precisar do mesmo valor em um componente, defina ele explicitamente como uma `prop` com um nome diferente:
252252

253253
```js{3,4}
254254
const content = posts.map((post) =>
@@ -259,11 +259,11 @@ const content = posts.map((post) =>
259259
);
260260
```
261261

262-
With the example above, the `Post` component can read `props.id`, but not `props.key`.
262+
No exemplo acima, o componente `Post` pode acessar `props.id`. Mas, não pode acessar `props.key`.
263263

264-
### Embedding map() in JSX {#embedding-map-in-jsx}
264+
### Incluindo map() no JSX {#incluindo-map-no-jsx}
265265

266-
In the examples above we declared a separate `listItems` variable and included it in JSX:
266+
Nos exemplos acima declaramos uma variável `listItems` separada e adicionamos ela no JSX:
267267

268268
```js{3-6}
269269
function NumberList(props) {
@@ -280,7 +280,7 @@ function NumberList(props) {
280280
}
281281
```
282282

283-
JSX allows [embedding any expression](/docs/introducing-jsx.html#embedding-expressions-in-jsx) in curly braces so we could inline the `map()` result:
283+
O JSX permite [incluir qualquer expressão](/docs/introducing-jsx.html#embedding-expressions-in-jsx) dentro de chaves, então podemos adicionar o resultado do `map()` diretamente:
284284

285285
```js{5-8}
286286
function NumberList(props) {
@@ -296,6 +296,6 @@ function NumberList(props) {
296296
}
297297
```
298298

299-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
299+
[**Experimente no CodePen**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
300300

301-
Sometimes this results in clearer code, but this style can also be abused. Like in JavaScript, it is up to you to decide whether it is worth extracting a variable for readability. Keep in mind that if the `map()` body is too nested, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
301+
Às vezes isso resulta em um código mais limpo. Mas esse padrão também pode ser confuso. Como em JavaScript, depende de você decidir se vale a pena extrair uma variável para aumentar a legibilidade. Lembre-se que se o corpo da função `map()` tiver muitos níveis, poderá ser um bom momento para [extrair um componente](/docs/components-and-props.html#extracting-components).

content/docs/nav.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- id: conditional-rendering
2727
title: Conditional Rendering
2828
- id: lists-and-keys
29-
title: Lists and Keys
29+
title: Listas e Chaves
3030
- id: forms
3131
title: Forms
3232
- id: lifting-state-up

0 commit comments

Comments
 (0)