Skip to content

Commit 54059f6

Browse files
Translate Importing and Exporting Components page (#658)
* docs(pt-br): Translates the importing-and-exporting-components page * fix(doc): WIP * [REFACTOR]: Applies requested changes * WIP
1 parent cddd0ed commit 54059f6

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

src/content/learn/importing-and-exporting-components.md

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
---
2-
title: Importing and Exporting Components
2+
title: Importando e Exportando Componentes
33
---
44

55
<Intro>
66

7-
The magic of components lies in their reusability: you can create components that are composed of other components. But as you nest more and more components, it often makes sense to start splitting them into different files. This lets you keep your files easy to scan and reuse components in more places.
7+
A magia dos componentes reside na sua habilidade de reutilização: você pode criar um componente que é composto por outros componentes. Mas conforme você aninha mais e mais componentes, faz sentido começar a dividi-los em arquivos diferentes. Isso permite que você mantenha seus arquivos fáceis de explorar e reutiliza-los em mais lugares.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
* What a root component file is
14-
* How to import and export a component
15-
* When to use default and named imports and exports
16-
* How to import and export multiple components from one file
17-
* How to split components into multiple files
13+
* O que é um arquivo de componente raiz
14+
* Como importar e exportar um componente
15+
* Quando usar importações e exportações padrão (`default`) e nomeada
16+
* Como importar e exportar múltiplos componentes em um arquivo
17+
* Como separar componentes em múltiplos arquivos
1818

1919
</YouWillLearn>
2020

21-
## The root component file {/*the-root-component-file*/}
21+
## O arquivo de componente raiz {/*the-root-component-file*/}
2222

23-
In [Your First Component](/learn/your-first-component), you made a `Profile` component and a `Gallery` component that renders it:
23+
Em [Seu Primeiro Componente](/learn/your-first-component), você criou um componente `Profile` e um componente `Gallery` que renderiza:
2424

2525
<Sandpack>
2626

@@ -37,7 +37,7 @@ function Profile() {
3737
export default function Gallery() {
3838
return (
3939
<section>
40-
<h1>Amazing scientists</h1>
40+
<h1>Cientistas incríveis</h1>
4141
<Profile />
4242
<Profile />
4343
<Profile />
@@ -52,17 +52,17 @@ img { margin: 0 10px 10px 0; height: 90px; }
5252

5353
</Sandpack>
5454

55-
These currently live in a **root component file,** named `App.js` in this example. In [Create React App](https://create-react-app.dev/), your app lives in `src/App.js`. Depending on your setup, your root component could be in another file, though. If you use a framework with file-based routing, such as Next.js, your root component will be different for every page.
55+
Atualmente, eles residem em um **arquivo de componente raiz,** chamado `App.js` nesse exemplo. Em [Criar Aplicação React](https://create-react-app.dev/), seu app reside em `src/App.js`. Dependendo da sua configuração, seu componente raiz pode estar em outro arquivo. Se você usar um framework com roteamento baseado em arquivo, como o Next.js, seu componente raiz será diferente para cada página.
5656

57-
## Exporting and importing a component {/*exporting-and-importing-a-component*/}
57+
## Exportando e importando um componente {/*exporting-and-importing-a-component*/}
5858

59-
What if you want to change the landing screen in the future and put a list of science books there? Or place all the profiles somewhere else? It makes sense to move `Gallery` and `Profile` out of the root component file. This will make them more modular and reusable in other files. You can move a component in three steps:
59+
E se você quiser mudar a tela inicial no futuro e colocar uma lista de livros de ciências lá? Ou colocar todos os perfis em outro lugar? Faz sentido mover `Gallery` e `Profile` para fora do arquivo do componente raiz. Isso os tornará mais modulares e reutilizáveis em outros arquivos. Você pode mover um componente em três etapas:
6060

61-
1. **Make** a new JS file to put the components in.
62-
2. **Export** your function component from that file (using either [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export) or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports) exports).
63-
3. **Import** it in the file where you’ll use the component (using the corresponding technique for importing [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults) or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module) exports).
61+
1. **Criar** um novo arquivo JS para colocar os componentes.
62+
2. **Exportar** seu componente de função desse arquivo (usando exportações [padrão](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export) ou [nomeada](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports)).
63+
3. **Importar** no arquivo onde você usará o componente (usando a técnica correspondente para importar exportações [padrão](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults) ou [nomeadas](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module)).
6464

65-
Here both `Profile` and `Gallery` have been moved out of `App.js` into a new file called `Gallery.js`. Now you can change `App.js` to import `Gallery` from `Gallery.js`:
65+
Aqui, tanto `Profile` e `Gallery` foram movidos de `App.js` para um novo arquivo chamado `Gallery.js`. Agora você pode alterar o arquivo `App.js` para importar o componente `Gallery` de `Gallery.js`:
6666

6767
<Sandpack>
6868

@@ -89,7 +89,7 @@ function Profile() {
8989
export default function Gallery() {
9090
return (
9191
<section>
92-
<h1>Amazing scientists</h1>
92+
<h1>Cientistas incríveis</h1>
9393
<Profile />
9494
<Profile />
9595
<Profile />
@@ -104,82 +104,82 @@ img { margin: 0 10px 10px 0; height: 90px; }
104104

105105
</Sandpack>
106106

107-
Notice how this example is broken down into two component files now:
107+
Observe como este exemplo é dividido em dois arquivos de componentes agora:
108108

109109
1. `Gallery.js`:
110-
- Defines the `Profile` component which is only used within the same file and is not exported.
111-
- Exports the `Gallery` component as a **default export.**
110+
- Define o componente `Profile` que é usado apenas dentro do mesmo arquivo e não é exportado.
111+
- Exporta o componente `Gallery` como uma **(default export).**
112112
2. `App.js`:
113-
- Imports `Gallery` as a **default import** from `Gallery.js`.
114-
- Exports the root `App` component as a **default export.**
113+
- Importa `Gallery` como uma **importação padrão** de `Gallery.js`.
114+
- Exporta o componente raiz `App` como uma **exportação padrão (default export).**
115115

116116

117117
<Note>
118118

119-
You may encounter files that leave off the `.js` file extension like so:
119+
Você pode encontrar arquivos que não possuem a extensão de arquivo `.js` da seguinte forma:
120120

121121
```js
122122
import Gallery from './Gallery';
123123
```
124124

125-
Either `'./Gallery.js'` or `'./Gallery'` will work with React, though the former is closer to how [native ES Modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules) work.
125+
Tanto `'./Gallery.js'` quanto `'./Gallery'` funcionarão com o React, embora o primeiro esteja mais próximo de como os [Módulos ES nativos](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules) funcionam.
126126

127127
</Note>
128128

129129
<DeepDive>
130130

131-
#### Default vs named exports {/*default-vs-named-exports*/}
131+
#### Exportação padrão vs nomeada {/*default-vs-named-exports*/}
132132

133-
There are two primary ways to export values with JavaScript: default exports and named exports. So far, our examples have only used default exports. But you can use one or both of them in the same file. **A file can have no more than one _default_ export, but it can have as many _named_ exports as you like.**
133+
Existem duas maneiras principais de exportar valores com JavaScript: exportações padrão e exportações nomeadas. Até agora, nossos exemplos usaram apenas exportações padrão. Mas você pode usar um ou ambos no mesmo arquivo. **Um arquivo não pode ter mais de uma exportação _padrão_, mas pode ter quantas exportações _nomeadas_ você desejar.**
134134

135-
![Default and named exports](/images/docs/illustrations/i_import-export.svg)
135+
![Exportações padrão e nomeadas](/images/docs/illustrations/i_import-export.svg)
136136

137-
How you export your component dictates how you must import it. You will get an error if you try to import a default export the same way you would a named export! This chart can help you keep track:
137+
A forma como você exporta seu componente determina como você deve importá-lo. Você receberá um erro se tentar importar uma exportação padrão da mesma forma que faria com uma exportação nomeada! Este gráfico pode ajudá-lo a acompanhar:
138138

139-
| Syntax | Export statement | Import statement |
140-
| ----------- | ----------- | ----------- |
141-
| Default | `export default function Button() {}` | `import Button from './Button.js';` |
142-
| Named | `export function Button() {}` | `import { Button } from './Button.js';` |
139+
| Sintase | Declaração de exportação | Declaração de importação |
140+
| ------- | ------------------------------------- | --------------------------------------- |
141+
| Padrão | `export default function Button() {}` | `import Button from './Button.js';` |
142+
| Nomeada | `export function Button() {}` | `import { Button } from './Button.js';` |
143143

144-
When you write a _default_ import, you can put any name you want after `import`. For example, you could write `import Banana from './Button.js'` instead and it would still provide you with the same default export. In contrast, with named imports, the name has to match on both sides. That's why they are called _named_ imports!
144+
Quando você escreve uma importação _padrão_, você pode colocar o nome que quiser depois de `import`. Por exemplo, você poderia escrever `import Banana from './Button.js'` e ainda forneceria a mesma exportação padrão. Por outro lado, com importações nomeadas, o nome deve corresponder em ambos os lados. É por isso que eles são chamados de importações _nomeadas_!
145145

146-
**People often use default exports if the file exports only one component, and use named exports if it exports multiple components and values.** Regardless of which coding style you prefer, always give meaningful names to your component functions and the files that contain them. Components without names, like `export default () => {}`, are discouraged because they make debugging harder.
146+
**Os usuários costumam usar exportações padrão se o arquivo exportar apenas um componente e usar exportações nomeadas se exportar vários componentes e valores.** Independentemente de qual estilo de código você preferir, sempre forneça nomes significativos para as funções do componente e os arquivos que os contêm. Componentes sem nomes, como `export default () => {}`, são desencorajados porque dificultam a depuração.
147147

148148
</DeepDive>
149149

150-
## Exporting and importing multiple components from the same file {/*exporting-and-importing-multiple-components-from-the-same-file*/}
150+
## Exportando e importando múltiplos componentes no mesmo arquivo {/*exporting-and-importing-multiple-components-from-the-same-file*/}
151151

152-
What if you want to show just one `Profile` instead of a gallery? You can export the `Profile` component, too. But `Gallery.js` already has a *default* export, and you can't have _two_ default exports. You could create a new file with a default export, or you could add a *named* export for `Profile`. **A file can only have one default export, but it can have numerous named exports!**
152+
E se você quiser mostrar apenas um `Profile` em vez de uma galeria? Você também pode exportar o componente `Profile`. Mas `Gallery.js` já tem uma exportação *padrão* e você não pode ter _duas_ exportações padrão. Você poderia criar um novo arquivo com uma exportação padrão ou adicionar uma exportação *nomeada* para `Profile`. **Um arquivo pode ter apenas uma exportação padrão, mas pode ter várias exportações nomeadas!**
153153

154154
<Note>
155155

156-
To reduce the potential confusion between default and named exports, some teams choose to only stick to one style (default or named), or avoid mixing them in a single file. Do what works best for you!
156+
Para reduzir a confusão potencial entre exportações padrão e nomeadas, algumas equipes optam por manter apenas um estilo (padrão ou nomeado) ou evitar misturá-los em um único arquivo. Faça o que for melhor para você!
157157

158158
</Note>
159159

160-
First, **export** `Profile` from `Gallery.js` using a named export (no `default` keyword):
160+
Primeiro, **exporte** `Profile` de `Gallery.js` usando uma exportação nomeada (sem a palavra-chave `default`):
161161

162162
```js
163163
export function Profile() {
164164
// ...
165165
}
166166
```
167167

168-
Then, **import** `Profile` from `Gallery.js` to `App.js` using a named import (with the curly braces):
168+
Então, **importe** `Profile` de `Gallery.js` para `App.js` usando uma importação nomeada (com chaves):
169169

170170
```js
171171
import { Profile } from './Gallery.js';
172172
```
173173

174-
Finally, **render** `<Profile />` from the `App` component:
174+
Finalmente, **renderize** `<Profile />` do componente `App`:
175175

176176
```js
177177
export default function App() {
178178
return <Profile />;
179179
}
180180
```
181181

182-
Now `Gallery.js` contains two exports: a default `Gallery` export, and a named `Profile` export. `App.js` imports both of them. Try editing `<Profile />` to `<Gallery />` and back in this example:
182+
Agora `Gallery.js` contém duas exportações: uma exportação `Gallery` padrão e uma exportação `Profile` nomeada. `App.js` importa ambos. Tente editar `<Profile />` para `<Gallery />` e vice-versa neste exemplo:
183183

184184
<Sandpack>
185185

@@ -207,7 +207,7 @@ export function Profile() {
207207
export default function Gallery() {
208208
return (
209209
<section>
210-
<h1>Amazing scientists</h1>
210+
<h1>Cientistas incríveis</h1>
211211
<Profile />
212212
<Profile />
213213
<Profile />
@@ -222,47 +222,47 @@ img { margin: 0 10px 10px 0; height: 90px; }
222222

223223
</Sandpack>
224224

225-
Now you're using a mix of default and named exports:
225+
Agora você esta usando uma mistura de exportações padrão e nomeadas:
226226

227227
* `Gallery.js`:
228-
- Exports the `Profile` component as a **named export called `Profile`.**
229-
- Exports the `Gallery` component as a **default export.**
228+
- Exporta o componente `Profile` como uma **exportação chamada `Profile`.**
229+
- Exporta o componente `Gallery` como uma **exportação padrão.**
230230
* `App.js`:
231-
- Imports `Profile` as a **named import called `Profile`** from `Gallery.js`.
232-
- Imports `Gallery` as a **default import** from `Gallery.js`.
233-
- Exports the root `App` component as a **default export.**
231+
- Importa `Profile` como uma **importação nomeada chamada `Profile`** de `Gallery.js`.
232+
- Importa `Gallery` como uma **importação padrão** de `Gallery.js`.
233+
- Exporta o componente raiz `App` como uma **exportação padrão.**
234234

235235
<Recap>
236236

237-
On this page you learned:
237+
Nessa pagina você aprendeu:
238238

239-
* What a root component file is
240-
* How to import and export a component
241-
* When and how to use default and named imports and exports
242-
* How to export multiple components from the same file
239+
* O que é um arquivo de componente raiz
240+
* Como importar e exportar um componente
241+
* Quando e como usar importações e exportações padrão e nomeada
242+
* Como exportar múltiplos componentes em um arquivo
243243

244244
</Recap>
245245

246246

247247

248248
<Challenges>
249249

250-
#### Split the components further {/*split-the-components-further*/}
250+
#### Divida os componentes ainda mais {/*split-the-components-further*/}
251251

252-
Currently, `Gallery.js` exports both `Profile` and `Gallery`, which is a bit confusing.
252+
Atualmente, `Gallery.js` exporta `Profile` e `Gallery`, o que é um pouco confuso.
253253

254-
Move the `Profile` component to its own `Profile.js`, and then change the `App` component to render both `<Profile />` and `<Gallery />` one after another.
254+
Mova o componente `Profile` para seu próprio `Profile.js` e, em seguida, altere o componente `App` para renderizar `<Profile />` e `<Gallery />` um após o outro.
255255

256-
You may use either a default or a named export for `Profile`, but make sure that you use the corresponding import syntax in both `App.js` and `Gallery.js`! You can refer to the table from the deep dive above:
256+
Você pode usar uma exportação padrão ou nomeada para `Profile`, mas certifique-se de usar a sintaxe de importação correspondente tanto em `App.js` e `Gallery.js`! Você pode consultar a tabela abaixo:
257257

258-
| Syntax | Export statement | Import statement |
259-
| ----------- | ----------- | ----------- |
260-
| Default | `export default function Button() {}` | `import Button from './Button.js';` |
261-
| Named | `export function Button() {}` | `import { Button } from './Button.js';` |
258+
| Sintase | Declaração de exportação | Declaração de importação |
259+
| ------- | ------------------------------------- | --------------------------------------- |
260+
| Padrão | `export default function Button() {}` | `import Button from './Button.js';` |
261+
| Nomeada | `export function Button() {}` | `import { Button } from './Button.js';` |
262262

263263
<Hint>
264264

265-
Don't forget to import your components where they are called. Doesn't `Gallery` use `Profile`, too?
265+
Não se esqueça de importar seus componentes onde eles são chamados. A `Gallery` também não usa `Profile`?
266266

267267
</Hint>
268268

@@ -295,7 +295,7 @@ export function Profile() {
295295
export default function Gallery() {
296296
return (
297297
<section>
298-
<h1>Amazing scientists</h1>
298+
<h1>Cientistas incríveis</h1>
299299
<Profile />
300300
<Profile />
301301
<Profile />
@@ -313,11 +313,11 @@ img { margin: 0 10px 10px 0; height: 90px; }
313313

314314
</Sandpack>
315315

316-
After you get it working with one kind of exports, make it work with the other kind.
316+
Depois de fazê-lo funcionar com um tipo de exportação, faça-o funcionar com o outro tipo.
317317

318318
<Solution>
319319

320-
This is the solution with named exports:
320+
Esta é a solução com exportações nomeadas:
321321

322322
<Sandpack>
323323

@@ -341,7 +341,7 @@ import { Profile } from './Profile.js';
341341
export default function Gallery() {
342342
return (
343343
<section>
344-
<h1>Amazing scientists</h1>
344+
<h1>Cientistas incríveis</h1>
345345
<Profile />
346346
<Profile />
347347
<Profile />
@@ -367,7 +367,7 @@ img { margin: 0 10px 10px 0; height: 90px; }
367367

368368
</Sandpack>
369369

370-
This is the solution with default exports:
370+
Esta é a solução com exportações padrão:
371371

372372
<Sandpack>
373373

@@ -391,7 +391,7 @@ import Profile from './Profile.js';
391391
export default function Gallery() {
392392
return (
393393
<section>
394-
<h1>Amazing scientists</h1>
394+
<h1>Cientistas incríveis</h1>
395395
<Profile />
396396
<Profile />
397397
<Profile />

0 commit comments

Comments
 (0)