Skip to content

Commit 7981daf

Browse files
authored
translate importing-exporting-components (#444)
* translate importing-exporting-components * translate importing-exporting-components fixes
1 parent 6e7c973 commit 7981daf

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

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

+68-68
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
---
2-
title: Importing and Exporting Components
2+
title: Importazione ed Esportazione di Componenti
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+
La magia dei componenti sta nella loro riutilizzabilità: si possono creare componenti che sono composti da altri componenti. Ma quando si annidano sempre più componenti, spesso ha senso iniziare a dividerli in file diversi. Ciò consente di mantenere i file facili da leggere e di riutilizzare i componenti in più punti.
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+
* Cos'è un file del componente radice
14+
* Come importare ed esportare un componente
15+
* Quando utilizzare importazioni ed esportazioni predefinite e nominali
16+
* Come importare ed esportare più componenti da un unico file
17+
* Come dividere i componenti in più file
1818

1919
</YouWillLearn>
2020

21-
## The root component file {/*the-root-component-file*/}
21+
## Il file del componente radice {/*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+
In [Il Tuo Primo Componente](/learn/your-first-component), hai creato un componente `Profile` e un componente `Gallery` che lo renderizza:
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>Scienziati incredibili</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+
Attualmente questi componenti si trovano nel **file del componente radice,** chiamato `App.js` in questo esempio. In [Create React App](https://create-react-app.dev/), l'applicazione si trova in `src/App.js`. Tuttavia, a seconda della configurazione, il componente radice potrebbe trovarsi in un altro file. Se si usa un framework con routing basato su file, come Next.js, il componente radice sarà diverso per ogni pagina.
5656

57-
## Exporting and importing a component {/*exporting-and-importing-a-component*/}
57+
## Esportazione e importazione di un 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 in futuro si volesse cambiare la schermata di landing e inserire un elenco di libri scientifici? O mettere tutti i profili da qualche altra parte? Avrebbe senso spostare `Gallery` e `Profile` dal file radice del componente. Far questo renderà tali componenti più modulari e riutilizzabili in altri file. È possibile spostare un componente in tre fasi:
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. **Crea** un nuovo file JS in cui inserire i componenti.
62+
2. **Esporta** la funzione del componente da quel file (utilizzando [l'esportazione predefinita](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export) o [nominale](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports)).
63+
3. **Importa** il componente nel file in cui lo si utilizzerà (utilizzando la tecnica corrispondente per l'importazione [predefinita](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults) o [nominale](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+
Qui sia `Profile` che `Gallery` sono stati spostati da `App.js` in un nuovo file chiamato `Gallery.js`. Ora si può modificare `App.js` per importare `Gallery` da `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>Scienziati incredibili</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+
Si noti come questo esempio sia ora suddiviso in due file componenti:
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+
- Definisce il componente `Profile` che viene utilizzato solo all'interno dello stesso file e non viene esportato.
111+
- Esporta il componente `Gallery` come **esportazione predefinita**.
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` come **importazione predefinita** da `Gallery.js`.
114+
- Esporta il componente `App` principale come **esportazione predefinita**.
115115

116116

117117
<Note>
118118

119-
You may encounter files that leave off the `.js` file extension like so:
119+
Si possono incontrare file che omettono l'estensione `.js` come in questo caso:
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+
Sia `'./Gallery.js'` che `'./Gallery'` funzioneranno con React, anche se il primo è più simile a come funzionano i [Moduli ES nativi](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules).
126126

127127
</Note>
128128

129129
<DeepDive>
130130

131-
#### Default vs named exports {/*default-vs-named-exports*/}
131+
#### Esportazioni predefinite o nominali {/*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+
Esistono due modi principali per esportare valori in JavaScript: le esportazioni predefinite e le esportazioni nominali. Finora, i nostri esempi hanno utilizzato solo le esportazioni predefinite. Ma è possibile utilizzare una o entrambe nello stesso file. **Un file non può avere più di un'esportazione _default_, ma può avere tutte le esportazioni _nominali_ che si vogliono**.
134134

135-
![Default and named exports](/images/docs/illustrations/i_import-export.svg)
135+
![Esportazioni predefinite e nominali](/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+
Il modo in cui si esporta il componente determina il modo in cui lo si deve importare. Si otterrà un errore se si cerca di importare un'esportazione predefinita nello stesso modo in cui si importerebbe un'esportazione nominale! Questo grafico può aiutarti a non confonderti:
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+
| Sintassi | Dichiarazione di esportazione | Dichiarazione di importazione |
140+
| ----------- | ----------- | ----------- |
141+
| Predefinita | `export default function Button() {}` | `import Button from './Button.js';` |
142+
| Nominale | `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 si utilizza un'importazione _default_, si può utilizzare qualsiasi nome si voglia dopo `import`. Per esempio, si potrebbe scrivere `import Banana from './Button.js'` e si otterrebbe comunque la stessa esportazione predefinita. Al contrario, con le importazioni nominali, il nome deve corrispondere da entrambe le parti. Ecco perché si chiamano importazioni _nominali_!
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+
**Spesso si utilizzano esportazioni predefinite se il file esporta un solo componente e esportazioni nominali se esporta più componenti e/o valori.** Indipendentemente dallo stile che si preferisce, bisogna sempre dare nomi significativi alle funzioni dei componenti e ai file che li contengono. I componenti senza nome, come `export default () => {}`, sono sconsigliati perché rendono più difficile il debugging.
147147

148148
</DeepDive>
149149

150-
## Exporting and importing multiple components from the same file {/*exporting-and-importing-multiple-components-from-the-same-file*/}
150+
## Esportazione e importazione di più componenti dallo stesso file {/*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 si volesse mostrare un solo `Profile` invece di una galleria? Si può esportare anche il componente `Profile`. Ma `Gallery.js` ha già un'esportazione *default* e non si possono avere due esportazioni predefinite. Si può creare un nuovo file con un'esportazione predefinita o aggiungere un'esportazione *nominale* per `Profile`. **Un file può avere una sola esportazione predefinita, ma può avere numerose esportazioni nominali!**
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+
Per ridurre la potenziale confusione tra esportazioni predefinite e nominali, alcuni team scelgono di attenersi a un solo stile (predefinito o nominale) o di evitare di mescolarli in un unico file. Fai quello che funziona meglio per te!
157157

158158
</Note>
159159

160-
First, **export** `Profile` from `Gallery.js` using a named export (no `default` keyword):
160+
Per prima cosa, **esporta** `Profile` da `Gallery.js` usando un'esportazione nominale (senza parola chiave `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+
Quindi, **importa** `Profile` da `Gallery.js` in `App.js` usando un'importazione nominale (con le parentesi graffe):
169169

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

174-
Finally, **render** `<Profile />` from the `App` component:
174+
Infine, **renderizza** `<Profile />` nel 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+
Ora `Gallery.js` contiene due esportazioni: una predefinita `Gallery` e una denominata `Profile`. `App.js` le importa entrambe. Prova a modificare `<Profile />` in `<Gallery />` e viceversa in questo esempio:
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>Scienziati incredibili</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+
Ora stai utilizzando un mix di esportazioni predefinite e nominate:
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+
- Esporta il componente `Profile` come un'esportazione **nominale chiamata `Profile`.**
229+
- Esporta il componente `Gallery` come **esportazione predefinita**.
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` come un'importazione **nominale chiamata `Profile`** da `Gallery.js`.
232+
- Importa `Gallery` come **importazione predefinita** da `Gallery.js`.
233+
- Esporta il componente `App` principale come **esportazione predefinita**.
234234

235235
<Recap>
236236

237-
On this page you learned:
237+
In questa pagina hai imparato:
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+
* Cos'è un file del componente radice
240+
* Come importare ed esportare un componente
241+
* Quando e come utilizzare importazioni ed esportazioni predefinite e nominali
242+
* Come esportare più componenti dallo stesso file
243243

244244
</Recap>
245245

246246

247247

248248
<Challenges>
249249

250-
#### Split the components further {/*split-the-components-further*/}
250+
#### Suddividere ulteriormente i componenti {/*split-the-components-further*/}
251251

252-
Currently, `Gallery.js` exports both `Profile` and `Gallery`, which is a bit confusing.
252+
Attualmente, `Gallery.js` esporta sia `Profile` che `Gallery`, il che crea un po' di confusione.
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+
Sposta il componente `Profile` nel proprio `Profile.js`, quindi modifica il componente `App` per renderizzare sia `<Profile />` che `<Gallery />` uno dopo l'altro.
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+
Puoi usare un'esportazione predefinita o nominale per `Profile`, ma assicurati di usare la sintassi di importazione corrispondente sia in `App.js` che in `Gallery.js`! Puoi fare riferimento alla tabella di approfondimento di cui sopra:
257257

258-
| Syntax | Export statement | Import statement |
258+
| Sintassi | Dichiarazione di esportazione | Dichiarazione di importazione |
259259
| ----------- | ----------- | ----------- |
260-
| Default | `export default function Button() {}` | `import Button from './Button.js';` |
261-
| Named | `export function Button() {}` | `import { Button } from './Button.js';` |
260+
| Predefinita | `export default function Button() {}` | `import Button from './Button.js';` |
261+
| Nominale | `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+
Non dimenticare di importare i componenti dove vengono chiamati. Anche `Gallery` 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>Scienziati incredibili</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+
Dopo aver fatto funzionare il tutto con un tipo di esportazioni, fallo funzionare con l'altro tipo.
317317

318318
<Solution>
319319

320-
This is the solution with named exports:
320+
Questa è la soluzione con le esportazioni nominali:
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>Scienziati incredibili</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+
Questa è la soluzione con le esportazioni predefinite:
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>Scienziati incredibili</h1>
395395
<Profile />
396396
<Profile />
397397
<Profile />

src/sidebarLearn.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"path": "/learn/your-first-component"
5757
},
5858
{
59-
"title": "Importing and Exporting Components",
59+
"title": "Importazione ed Esportazione di Componenti",
6060
"path": "/learn/importing-and-exporting-components"
6161
},
6262
{

0 commit comments

Comments
 (0)