You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/describing-the-ui.md
+49-47Lines changed: 49 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,29 @@
1
1
---
2
-
title: Describing the UI
2
+
title: Construindo a UI
3
3
---
4
4
5
5
<Intro>
6
6
7
-
React is a JavaScript library for rendering user interfaces (UI). UI is built from small units like buttons, text, and images. React lets you combine them into reusable, nestable *components.*From web sites to phone apps, everything on the screen can be broken down into components. In this chapter, you'll learn to create, customize, and conditionally display React components.
7
+
React é uma biblioteca JavaScript para renderizar interfaces de usuário (UI). A interface do usuário é construída a partir de pequenas unidades, como botões, texto e imagens. O React permite combiná-los em *componentes.*encaixáveis e reutilizáveis. De sites a aplicativos de telefone, tudo na tela pode ser dividido em componentes. Neste capítulo, você aprenderá a criar, personalizar e exibir componentes React condicionalmente.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearnisChapter={true}>
12
12
13
-
*[How to write your first React component](/learn/your-first-component)
14
-
*[When and how to create multi-component files](/learn/importing-and-exporting-components)
15
-
*[How to add markup to JavaScript with JSX](/learn/writing-markup-with-jsx)
16
-
*[How to use curly braces with JSX to access JavaScript functionality from your components](/learn/javascript-in-jsx-with-curly-braces)
17
-
*[How to configure components with props](/learn/passing-props-to-a-component)
18
-
*[How to conditionally render components](/learn/conditional-rendering)
19
-
*[How to render multiple components at a time](/learn/rendering-lists)
20
-
*[How to avoid confusing bugs by keeping components pure](/learn/keeping-components-pure)
13
+
*[Como criar seu primeiro componente React](/learn/your-first-component)
14
+
*[Quando e como criar múltiplos componentes](/learn/importing-and-exporting-components)
15
+
*[Como escrever tags dentro do JavaScript usando JSX](/learn/writing-markup-with-jsx)
16
+
*[Como utilizar chaves no JSX para utilizar funcões JavaScript nos seus componentes](/learn/javascript-in-jsx-with-curly-braces)
*[Como renderizar componentes de forma condicional](/learn/conditional-rendering)
19
+
*[Como renderizar múltiplos componentes de uma só vez](/learn/rendering-lists)
20
+
*[Como evitar comportamentos inesperados mantendo seus componentes puros](/learn/keeping-components-pure)
21
21
22
22
</YouWillLearn>
23
23
24
-
## Your first component {/*your-first-component*/}
25
-
26
-
React applications are built from isolated pieces of UI called *components*. A React component is a JavaScript function that you can sprinkle with markup. Components can be as small as a button, or as large as an entire page. Here is a `Gallery` component rendering three `Profile` components:
24
+
## Seu Primeiro Componente {/*your-first-component*/}
27
25
26
+
Aplicações React são construídas a partir de partes isoladas da UI chamadas de *componentes*. Um componente React é uma função JavaScript que você pode usar em combinação com tags. Os componentes podem ser tão pequenos quanto um botão ou tão grandes quanto uma página inteira. Abaixo você pode ver um componente `Gallery` renderizando três componentes `Profile`:
Read**[Your First Component](/learn/your-first-component)**to learn how to declare and use React components.
59
+
Leia**[Seu Primeiro Componente](/learn/your-first-component)**para aprender como criar e usar componentes React.
61
60
62
61
</LearnMore>
63
62
64
-
## Importing and exporting components {/*importing-and-exporting-components*/}
63
+
## Importando e Exportando Componentes {/*importing-and-exporting-components*/}
65
64
66
-
You can declare many components in one file, but large files can get difficult to navigate. To solve this, you can *export* a component into its own file, and then *import* that component from another file:
65
+
Você pode declarar vários componentes em um único arquivo, mas arquivos grandes podem ser difíceis de navegar. Para resolver isso, você pode *exportar* um componente para um arquivo separado, e então *importar* este componente em outro arquivo:
Read**[Importing and Exporting Components](/learn/importing-and-exporting-components)**to learn how to split components into their own files.
114
+
Leia**[Importando e Exportando Componentes](/learn/importing-and-exporting-components)**para aprender como separar seus componentes em arquivos próprios.
116
115
117
116
</LearnMore>
118
117
119
-
## Writing markup with JSX {/*writing-markup-with-jsx*/}
118
+
## Escrevendo Tags com JSX {/*writing-markup-with-jsx*/}
120
119
121
-
Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information.
120
+
Cada componente React é uma função JavaScript que pode conter tags que o React renderiza no navegador. Componentes React utilizam uma extensão de sintaxe chamada JSX para representar essas tags. JSX parece muito com HTML, mas é um pouco mais rígido e pode exibir informações de forma dinâmica.
122
121
123
-
If we paste existing HTML markup into a React component, it won't always work:
122
+
Nem sempre colar um HTML pré-existente irá funcionar em um componente React:
124
123
125
124
<Sandpack>
126
125
127
126
```js
128
127
exportdefaultfunctionTodoList() {
129
128
return (
130
-
//This doesn't quite work!
129
+
//Isto não vai funcionar!
131
130
<h1>Hedy Lamarr's Todos</h1>
132
131
<img
133
132
src="https://i.imgur.com/yXOvdOSs.jpg"
@@ -149,7 +148,7 @@ img { height: 90px; }
149
148
150
149
</Sandpack>
151
150
152
-
If you have existing HTML like this, you can fix it using a [converter](https://transform.tools/html-to-jsx):
151
+
Você pode consertar seu HTML pré-existente usando um [conversor](https://transform.tools/html-to-jsx):
153
152
154
153
<Sandpack>
155
154
@@ -181,13 +180,13 @@ img { height: 90px; }
181
180
182
181
<LearnMorepath="/learn/writing-markup-with-jsx">
183
182
184
-
Read**[Writing Markup with JSX](/learn/writing-markup-with-jsx)**to learn how to write valid JSX.
183
+
Leia**[Escrevendo Tags com JSX](/learn/writing-markup-with-jsx)**para aprender como escrever JSX corretamente.
185
184
186
185
</LearnMore>
187
186
188
-
## JavaScript in JSX with curly braces {/*javascript-in-jsx-with-curly-braces*/}
187
+
## JavaScript entre Chaves no JSX {/*javascript-in-jsx-with-curly-braces*/}
189
188
190
-
JSX lets you write HTML-like markup inside a JavaScript file, keeping rendering logic and content in the same place. Sometimes you will want to add a little JavaScript logic or reference a dynamic property inside that markup. In this situation, you can use curly braces in your JSX to "open a window" to JavaScript:
189
+
JSX permite que você escreva de maneira análoga ao HTML dentro de um arquivo JavaScript, mantendo a lógica de renderização e o conteúdo no mesmo lugar. Em alguns momentos, você pode querer adicionar alguma lógica JavaScript ou uma propriedade dinâmica em uma tag. Neste tipo de situação, você pode utilizar chaves no JSX para "abrir uma janela" que entenda JavaScript:
191
190
192
191
<Sandpack>
193
192
@@ -229,13 +228,13 @@ body > div > div { padding: 20px; }
Read **[JavaScript in JSX with Curly Braces](/learn/javascript-in-jsx-with-curly-braces)** to learn how to access JavaScript data from JSX.
231
+
Leia **[JavaScript entre Chaves no JSX](/learn/javascript-in-jsx-with-curly-braces)** para aprender como acessar dados do seu código JavaScript a partir do JSX.
233
232
234
233
</LearnMore>
235
234
236
-
## Passing props to a component {/*passing-props-to-a-component*/}
235
+
## Passando Props para um Componente {/*passing-props-to-a-component*/}
237
236
238
-
React components use *props* to communicate with each other. Every parent component can pass some information to its child components by giving them props. Props might remind you of HTML attributes, but you can pass any JavaScript value through them, including objects, arrays, functions, and even JSX!
237
+
Componentes React utilizam *propriedades (props)* para se comunicarem entre si. Cada componente pai pode passar informações para seus componentes filhos por meio de props. Props lembram um pouco os atributos HTML, mas você pode passar qualquer valor que seja válido em JavaScript por meio delas, incluindo objetos, arrays, funções e até mesmo JSX!
Frequentemente você vai precisar exibir diferentes conteúdos nos seus componentes de acordo com certas condições. No React, você pode renderizar JSX condicionalmente utilizando uma sintaxe parecida com JavaScript, que usa o comando `if`, e operadores lógicos `&&` e `? :`.
318
319
319
-
Your components will often need to display different things depending on different conditions. In React, you can conditionally render JSX using JavaScript syntax like `if` statements, `&&`, and `? :` operators.
320
+
Neste exemplo, o operador JavaScript `&&` é utilizado para renderizar condicionalmente um marcação de 'concluído':
320
321
321
-
In this example, the JavaScript `&&` operator is used to conditionally render a checkmark:
322
322
323
323
<Sandpack>
324
324
@@ -358,15 +358,16 @@ export default function PackingList() {
358
358
359
359
<LearnMore path="/learn/conditional-rendering">
360
360
361
-
Read **[Conditional Rendering](/learn/conditional-rendering)** to learn the different ways to render content conditionally.
361
+
Leia **[Renderização Condicional](/learn/conditional-rendering)** para aprender diferentes maneiras de renderizar um conteúdo de forma condicional.
362
362
363
363
</LearnMore>
364
364
365
-
## Rendering lists {/*rendering-lists*/}
365
+
## Renderizando Listas {/*rendering-lists*/}
366
366
367
-
You will often want to display multiple similar components from a collection of data. You can use JavaScript's `filter()` and `map()`with React to filter and transform your array of data into an array of components.
367
+
Frequentemente você vai desejar exibir vários componentes similares a partir de uma lista de dados. Você pode utilizar as funções `filter()` e `map()` do JavaScript no React para filtrar e transformar suas listas de dados em listas de componentes.
368
+
369
+
Para cada item da lista, você precisa especificar uma chave (`key`). Normalmente é desejável que você use um ID do seu banco de dados como `key`. Chaves permitem que o React rastreie o local de cada item da lista, mesmo que a lista mude.
368
370
369
-
For each array item, you will need to specify a `key`. Usually, you will want to use an ID from the database as a `key`. Keyslet React keep track of each item's place in the list even if the list changes.
370
371
371
372
<Sandpack>
372
373
@@ -458,18 +459,19 @@ h2 { font-size: 20px; }
458
459
459
460
<LearnMorepath="/learn/rendering-lists">
460
461
461
-
Read**[Rendering Lists](/learn/rendering-lists)**to learn how to render a list of components, and how to choose a key.
462
+
Leia**[Renderizando Listas](/learn/rendering-lists)**para aprender como renderizar uma lista de compomentes e como escolher uma chave para cada item da lista.
462
463
463
464
</LearnMore>
464
465
465
-
## Keeping components pure {/*keeping-components-pure*/}
466
+
## Mantendo Seus Componentes Puros {/*keeping-components-pure*/}
467
+
468
+
Algumas funções JavaScript são *puras*. Uma função pura:
466
469
467
-
Some JavaScript functions are *pure.* A pure function:
468
470
469
-
***Minds its own business.**It does not change any objects or variables that existed before it was called.
470
-
***Same inputs, same output.**Given the same inputs, a pure function should always return the same result.
471
+
***Cuida apenas de suas próprias responsabilidades.**Isso significa que ela não modifica nenhum objeto ou variável que existia antes que ela fosse chamada.
472
+
***Mesmas entradas, mesma saída.**Dadas as mesmas entradas, uma função pura sempre deve retornar o mesmo resultado.
471
473
472
-
By strictly only writing your components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. Here is an example of an impure component:
474
+
Escrevendo apenas funções puras, você pode evitar muitos erros e comportamentos imprevisíveis conforme seu código aumenta. Este é um exemplo de componente impuro:
473
475
474
476
<Sandpack>
475
477
@@ -495,7 +497,7 @@ export default function TeaSet() {
495
497
496
498
</Sandpack>
497
499
498
-
You can make this component pure by passing a prop instead of modifying a preexisting variable:
500
+
Você pode tornar esse componente puro passando uma prop ao invés de modificar uma variável pré-existente:
499
501
500
502
<Sandpack>
501
503
@@ -519,12 +521,12 @@ export default function TeaSet() {
519
521
520
522
<LearnMorepath="/learn/keeping-components-pure">
521
523
522
-
Read**[Keeping Components Pure](/learn/keeping-components-pure)**to learn how to write components as pure, predictable functions.
524
+
Leia**[Mantendo Seus Componentes Puros](/learn/keeping-components-pure)**para aprender como criar componentes puros e funções previsíveis.
523
525
524
526
</LearnMore>
525
527
526
-
## What's next? {/*whats-next*/}
528
+
## O que vem depois? {/*whats-next*/}
527
529
528
-
Head over to [Your First Component](/learn/your-first-component)to start reading this chapter page by page!
530
+
Navegue para a página [Seu Primeiro Componente](/learn/your-first-component)para começar a ler esse capítulo página por página!
529
531
530
-
Or, if you're already familiar with these topics, why not read about [Adding Interactivity](/learn/adding-interactivity)?
532
+
Ou, se você já tem familirialidade com estes tópicos, por quê não ler sobre [Adicionando Interatividade](/learn/adding-interactivity)?
0 commit comments