Skip to content

Commit 9194530

Browse files
deblasisLucaBlackDragon
authored andcommitted
Translation for the page 'Components and props' (#101)
* components-and-props: wip * WIP: components-and-props * components-and-props: done * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]> * Update content/docs/components-and-props.md Co-Authored-By: deblasis <[email protected]>
1 parent 193a1b2 commit 9194530

File tree

4 files changed

+106
-105
lines changed

4 files changed

+106
-105
lines changed

Diff for: GLOSSARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Suggestion on words and terms:
3131
| render | renderizzare (verbo), renderizzato (nome) |
3232
| React component class | classe componente React |
3333
| React component type | tipo componente React |
34+
| function component | componente funzione |
3435

3536
## Problematic terms
3637

Diff for: content/docs/components-and-props.md

+102-102
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: components-and-props
3-
title: Components and Props
3+
title: Componenti e Props
44
permalink: docs/components-and-props.html
55
redirect_from:
66
- "docs/reusable-components.html"
@@ -16,98 +16,98 @@ prev: rendering-elements.html
1616
next: state-and-lifecycle.html
1717
---
1818

19-
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to the idea of components. You can find a [detailed component API reference here](/docs/react-component.html).
19+
I Componenti ti permettono di suddividere la UI (*User Interface*, o interfaccia utente) in parti indipendenti, riutilizzabili e di pensare ad ognuna di esse in modo isolato. Questa pagina offre una introduzione al concetto dei componenti. Puoi trovare invece informazioni dettagliate nella [API di riferimento dei componenti](/docs/react-component.html).
2020

21-
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen.
21+
Concettualmente, i componenti sono come funzioni JavaScript: accettano in input dati arbitrari (sotto il nome di "props") e ritornano elementi React che descrivono cosa dovrebbe apparire sullo schermo.
2222

23-
## Function and Class Components {#function-and-class-components}
23+
## Funzioni e Classi Componente {#function-and-class-components}
2424

25-
The simplest way to define a component is to write a JavaScript function:
25+
Il modo più semplice di definire un componente è quello di scrivere una funzione JavaScript:
2626

2727
```js
28-
function Welcome(props) {
29-
return <h1>Hello, {props.name}</h1>;
28+
function Ciao(props) {
29+
return <h1>Ciao, {props.nome}</h1>;
3030
}
3131
```
3232

33-
This function is a valid React component because it accepts a single "props" (which stands for properties) object argument with data and returns a React element. We call such components "function components" because they are literally JavaScript functions.
33+
Questa funzione è un componente React valido in quanto accetta un oggetto parametro contenente dati sotto forma di una singola "props" (che prende il nome da "properties" in inglese, ossia "proprietà") che è un oggetto parametro avente dati al suo interno e ritorna un elemento React. Chiameremo questo tipo di componenti "componenti funzione" perchè sono letteralmente funzioni JavaScript.
3434

35-
You can also use an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes) to define a component:
35+
Puoi anche usare una [classe ES6](https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Classes) per definire un componente:
3636

3737
```js
38-
class Welcome extends React.Component {
38+
class Ciao extends React.Component {
3939
render() {
40-
return <h1>Hello, {this.props.name}</h1>;
40+
return <h1>Ciao, {this.props.nome}</h1>;
4141
}
4242
}
4343
```
4444

45-
The above two components are equivalent from React's point of view.
45+
I due componenti appena visti sono equivalenti dal pundo di vista di React.
4646

47-
Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use function components for their conciseness.
47+
Le Classi hanno funzionalità aggiuntive che verranno discusse in dettaglio nelle [prossime sezioni](/docs/state-and-lifecycle.html). Fino ad allora, ci limiteremo all'uso dei componenti funzione per via della loro concisività.
4848

49-
## Rendering a Component {#rendering-a-component}
49+
## Renderizzare un Componente {#rendering-a-component}
5050

51-
Previously, we only encountered React elements that represent DOM tags:
51+
In precedenza, abbiamo incontrato elementi React che rappresentano tags DOM:
5252

5353
```js
54-
const element = <div />;
54+
const elemento = <div />;
5555
```
5656

57-
However, elements can also represent user-defined components:
57+
Comunque, gli elementi possono rappresentare anche componenti definiti dall'utente:
5858

5959
```js
60-
const element = <Welcome name="Sara" />;
60+
const elemento = <Ciao nome="Sara" />;
6161
```
6262

63-
When React sees an element representing a user-defined component, it passes JSX attributes to this component as a single object. We call this object "props".
63+
Quando React incontra un elemento che rappresenta un componente definito dall'utente, passa gli attributi JSX a questo componente come un singolo oggetto. Tale oggetto prende il nome di "props".
6464

65-
For example, this code renders "Hello, Sara" on the page:
65+
Ad esempio, il codice seguente renderizza il messaggio "Ciao, Sara" nella pagina:
6666

6767
```js{1,5}
68-
function Welcome(props) {
69-
return <h1>Hello, {props.name}</h1>;
68+
function Ciao(props) {
69+
return <h1>Ciao, {props.nome}</h1>;
7070
}
7171
72-
const element = <Welcome name="Sara" />;
72+
const elemento = <Ciao nome="Sara" />;
7373
ReactDOM.render(
74-
element,
74+
elemento,
7575
document.getElementById('root')
7676
);
7777
```
7878

79-
[](codepen://components-and-props/rendering-a-component)
79+
[**Prova in CodePen**](codepen://components-and-props/rendering-a-component)
8080

81-
Let's recap what happens in this example:
81+
Ricapitoliamo cosa succede nell'esempio:
8282

83-
1. We call `ReactDOM.render()` with the `<Welcome name="Sara" />` element.
84-
2. React calls the `Welcome` component with `{name: 'Sara'}` as the props.
85-
3. Our `Welcome` component returns a `<h1>Hello, Sara</h1>` element as the result.
86-
4. React DOM efficiently updates the DOM to match `<h1>Hello, Sara</h1>`.
83+
1. Richiamiamo `ReactDOM.render()` con l'elemento `<Ciao nome="Sara" />`.
84+
2. React chiama a sua volta il componente `Ciao` con `{nome: 'Sara'}` passato in input come props.
85+
3. Il nostro componente `Ciao` ritorna un elemento `<h1>Ciao, Sara</h1>` come risultato.
86+
4. React DOM aggiorna efficientemente il DOM per far sì che contenga `<h1>Ciao, Sara</h1>`.
8787

88-
>**Note:** Always start component names with a capital letter.
88+
>**Nota Bene:** Ricordati di chiamare i tuoi componenti con la prima lettera in maiuscolo.
8989
>
90-
>React treats components starting with lowercase letters as DOM tags. For example, `<div />` represents an HTML div tag, but `<Welcome />` represents a component and requires `Welcome` to be in scope.
90+
>React tratta i componenti che iniziano con una lettera minuscola come normali tags DOM. per esempio, `<div />` rappresenta un tag HTML div, `<Ciao />` rappresenta invece un componente e richiede `Ciao` all'interno dello [scope](https://developer.mozilla.org/en-US/docs/Glossary/Scope).
9191
>
92-
>To learn more about the reasoning behind this convention, please read [JSX In Depth](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized).
92+
>Per saperne di più riguardo questa convenzione, leggi [JSX In Dettaglio](/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized).
9393
94-
## Composing Components {#composing-components}
94+
## Comporre Componenti {#composing-components}
9595

96-
Components can refer to other components in their output. This lets us use the same component abstraction for any level of detail. A button, a form, a dialog, a screen: in React apps, all those are commonly expressed as components.
96+
I componenti possono far riferimento ad altri componenti nel loro output. Ciò permette di utilizzare la stessa astrazione ad ogni livello di dettaglio. Un bottone, un form, una finestra di dialogo, una schermata: nelle applicazioni React, tutte queste cose di solito sono espresse come componenti.
9797

98-
For example, we can create an `App` component that renders `Welcome` many times:
98+
Per esempio, possiamo creare un componente `App` che renderizza `Ciao` tante volte:
9999

100100
```js{8-10}
101-
function Welcome(props) {
102-
return <h1>Hello, {props.name}</h1>;
101+
function Ciao(props) {
102+
return <h1>Ciao, {props.nome}</h1>;
103103
}
104104
105105
function App() {
106106
return (
107107
<div>
108-
<Welcome name="Sara" />
109-
<Welcome name="Cahal" />
110-
<Welcome name="Edite" />
108+
<Ciao nome="Sara" />
109+
<Ciao nome="Cahal" />
110+
<Ciao nome="Edite" />
111111
</div>
112112
);
113113
}
@@ -118,145 +118,145 @@ ReactDOM.render(
118118
);
119119
```
120120

121-
[](codepen://components-and-props/composing-components)
121+
[**Prova in CodePen**](codepen://components-and-props/composing-components)
122122

123-
Typically, new React apps have a single `App` component at the very top. However, if you integrate React into an existing app, you might start bottom-up with a small component like `Button` and gradually work your way to the top of the view hierarchy.
123+
Normalmente, le nuove applicazioni React hanno un singolo componente chiamato `App` al livello più alto che racchiude tutti gli altri componenti. Ad ogni modo, quando si va ad integrare React in una applicazione già esistente, è bene partire dal livello più basso e da piccoli componenti come ad esempio `Bottone` procedendo da lì fino alla cima della gerarchia della vista.
124124

125-
## Extracting Components {#extracting-components}
125+
## Estrarre Componenti {#extracting-components}
126126

127-
Don't be afraid to split components into smaller components.
127+
Non aver paura di suddividere i componenti in componenti più piccoli.
128128

129-
For example, consider this `Comment` component:
129+
Ad esempio, considera questo componente `Commento`:
130130

131131
```js
132-
function Comment(props) {
132+
function Commento(props) {
133133
return (
134-
<div className="Comment">
135-
<div className="UserInfo">
134+
<div className="Commento">
135+
<div className="InfoUtente">
136136
<img className="Avatar"
137-
src={props.author.avatarUrl}
138-
alt={props.author.name}
137+
src={props.autore.avatarUrl}
138+
alt={props.autore.nome}
139139
/>
140-
<div className="UserInfo-name">
141-
{props.author.name}
140+
<div className="InfoUtente-nome">
141+
{props.autore.nome}
142142
</div>
143143
</div>
144-
<div className="Comment-text">
145-
{props.text}
144+
<div className="Commento-testo">
145+
{props.testo}
146146
</div>
147-
<div className="Comment-date">
148-
{formatDate(props.date)}
147+
<div className="Commento-data">
148+
{formatDate(props.data)}
149149
</div>
150150
</div>
151151
);
152152
}
153153
```
154154

155-
[](codepen://components-and-props/extracting-components)
155+
[**Prova in CodePen**](codepen://components-and-props/extracting-components)
156156

157-
It accepts `author` (an object), `text` (a string), and `date` (a date) as props, and describes a comment on a social media website.
157+
Esso accetta come props: `autore` (un oggetto), `testo` (una stringa) e `data` (sotto forma di oggetto [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)) al fine di renderizzare un commento in un sito di social media, come Facebook.
158158

159-
This component can be tricky to change because of all the nesting, and it is also hard to reuse individual parts of it. Let's extract a few components from it.
159+
Un componente scritto in quel modo, con codice molto annidato, è difficile da modificare. Per lo stesso motivo, non si possono riutilizzare con facilità parti dello stesso. Procediamo quindi ad estrarre qualche componente.
160160

161-
First, we will extract `Avatar`:
161+
Per cominciare, estraiamo `Avatar`:
162162

163163
```js{3-6}
164164
function Avatar(props) {
165165
return (
166166
<img className="Avatar"
167-
src={props.user.avatarUrl}
168-
alt={props.user.name}
167+
src={props.utente.avatarUrl}
168+
alt={props.utente.nome}
169169
/>
170170
);
171171
}
172172
```
173173

174-
The `Avatar` doesn't need to know that it is being rendered inside a `Comment`. This is why we have given its prop a more generic name: `user` rather than `author`.
174+
`Avatar` non ha bisogno di sapere che viene renderizzato all'interno di un `Commento`. Ecco perchè abbiamo dato alla sua prop un nome più generico: `utente` al posto di `autore`.
175175

176-
We recommend naming props from the component's own point of view rather than the context in which it is being used.
176+
Consigliamo di dare il nome alle props dal punto di vista del componente piuttosto che dal contesto in cui viene usato.
177177

178-
We can now simplify `Comment` a tiny bit:
178+
Adesso possiamo semplificare un po' il componente `Commento`:
179179

180180
```js{5}
181-
function Comment(props) {
181+
function Commento(props) {
182182
return (
183-
<div className="Comment">
184-
<div className="UserInfo">
185-
<Avatar user={props.author} />
186-
<div className="UserInfo-name">
187-
{props.author.name}
183+
<div className="Commento">
184+
<div className="InfoUtente">
185+
<Avatar utente={props.autore} />
186+
<div className="InfoUtente-nome">
187+
{props.autore.nome}
188188
</div>
189189
</div>
190-
<div className="Comment-text">
191-
{props.text}
190+
<div className="Commento-testo">
191+
{props.testo}
192192
</div>
193-
<div className="Comment-date">
194-
{formatDate(props.date)}
193+
<div className="Commento-data">
194+
{formatDate(props.data)}
195195
</div>
196196
</div>
197197
);
198198
}
199199
```
200200

201-
Next, we will extract a `UserInfo` component that renders an `Avatar` next to the user's name:
201+
Andiamo ora ad estrarre il componente `InfoUtente` che renderizza un `Avatar` vicino al nome dell'utente:
202202

203203
```js{3-8}
204-
function UserInfo(props) {
204+
function InfoUtente(props) {
205205
return (
206-
<div className="UserInfo">
207-
<Avatar user={props.user} />
208-
<div className="UserInfo-name">
209-
{props.user.name}
206+
<div className="InfoUtente">
207+
<Avatar utente={props.utente} />
208+
<div className="InfoUtente-nome">
209+
{props.utente.nome}
210210
</div>
211211
</div>
212212
);
213213
}
214214
```
215215

216-
This lets us simplify `Comment` even further:
216+
Ciò ci permette di semplificare `Commento` ancora di più:
217217

218218
```js{4}
219-
function Comment(props) {
219+
function Commento(props) {
220220
return (
221-
<div className="Comment">
222-
<UserInfo user={props.author} />
223-
<div className="Comment-text">
224-
{props.text}
221+
<div className="Commento">
222+
<InfoUtente utente={props.autore} />
223+
<div className="Commento-testo">
224+
{props.testo}
225225
</div>
226-
<div className="Comment-date">
227-
{formatDate(props.date)}
226+
<div className="Commento-data">
227+
{formatDate(props.data)}
228228
</div>
229229
</div>
230230
);
231231
}
232232
```
233233

234-
[](codepen://components-and-props/extracting-components-continued)
234+
[**Prova in CodePen**](codepen://components-and-props/extracting-components-continued)
235235

236-
Extracting components might seem like grunt work at first, but having a palette of reusable components pays off in larger apps. A good rule of thumb is that if a part of your UI is used several times (`Button`, `Panel`, `Avatar`), or is complex enough on its own (`App`, `FeedStory`, `Comment`), it is a good candidate to be a reusable component.
236+
Estrarre componenti può semprare un'attività pesante ma avere una tavolozza di componenti riutilizzabili ripaga molto bene nelle applicazioni più complesse. Una buona regola da tenere a mente è che se una parte della tua UI viene usata diverse volte (`Bottone`, `Pannello`, `Avatar`) o se è abbastanza complessa di per sé (`App`, `StoriaFeed`, `Commento`), allora questi componenti sono buoni candidati ad essere riutilizzabili.
237237

238-
## Props are Read-Only {#props-are-read-only}
238+
## Le Props Sono in Sola Lettura {#props-are-read-only}
239239

240-
Whether you declare a component [as a function or a class](#function-and-class-components), it must never modify its own props. Consider this `sum` function:
240+
Ogni volta che dichiari un componente [come funzione o classe](#function-and-class-components), non deve mai modificare le proprie props. Considera la funzione `somma`:
241241

242242
```js
243-
function sum(a, b) {
243+
function somma(a, b) {
244244
return a + b;
245245
}
246246
```
247247

248-
Such functions are called ["pure"](https://en.wikipedia.org/wiki/Pure_function) because they do not attempt to change their inputs, and always return the same result for the same inputs.
248+
Funzioni di questo tipo vengono chiamate ["pure"](https://en.wikipedia.org/wiki/Pure_function) perché non provano a cambiare i propri dati in input, ritornano sempre lo stesso risultato a partire dagli stessi dati in ingresso.
249249

250-
In contrast, this function is impure because it changes its own input:
250+
Al contrario, la funzione seguente è impura in quanto altera gli input:
251251

252252
```js
253-
function withdraw(account, amount) {
254-
account.total -= amount;
253+
function preleva(conto, ammontare) {
254+
conto.totale -= ammontare;
255255
}
256256
```
257257

258-
React is pretty flexible but it has a single strict rule:
258+
React è abbastanza flessibile ma ha una sola regola molto importante:
259259

260-
**All React components must act like pure functions with respect to their props.**
260+
**Tutti i componenti React devono comportarsi come funzioni pure rispetto alle proprie props.**
261261

262-
Of course, application UIs are dynamic and change over time. In the [next section](/docs/state-and-lifecycle.html), we will introduce a new concept of "state". State allows React components to change their output over time in response to user actions, network responses, and anything else, without violating this rule.
262+
Ovviamente, le UI delle applicazioni sono dinamiche e cambiano nel tempo. Nella [prossima sezione](/docs/state-and-lifecycle.html), introdurremo il nuovo concetto di "stato". Lo stato permette ai componenti React di modificare il loro output nel tempo in seguito ad azioni dell'utente, risposte dalla rete (API) e qualsiasi altra cosa possa far renderizzare un output diverso di volta in volta, ciò avviene senza violare questa regola molto importante.

Diff for: content/docs/nav.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- id: rendering-elements
1919
title: Renderizzare Elementi
2020
- id: components-and-props
21-
title: Components and Props
21+
title: Componenti e Props
2222
- id: state-and-lifecycle
2323
title: State and Lifecycle
2424
- id: handling-events

Diff for: content/docs/reference-react-component.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ redirect_from:
1515
- "tips/use-react-with-other-libraries.html"
1616
---
1717

18-
This page contains a detailed API reference for the React component class definition. It assumes you're familiar with fundamental React concepts, such as [Components and Props](/docs/components-and-props.html), as well as [State and Lifecycle](/docs/state-and-lifecycle.html). If you're not, read them first.
18+
This page contains a detailed API reference for the React component class definition. It assumes you're familiar with fundamental React concepts, such as [Componenti e Props](/docs/components-and-props.html), as well as [State and Lifecycle](/docs/state-and-lifecycle.html). If you're not, read them first.
1919

2020
## Overview {#overview}
2121

@@ -627,7 +627,7 @@ The `displayName` string is used in debugging messages. Usually, you don't need
627627

628628
### `props` {#props}
629629

630-
`this.props` contains the props that were defined by the caller of this component. See [Components and Props](/docs/components-and-props.html) for an introduction to props.
630+
`this.props` contains the props that were defined by the caller of this component. See [Componenti e Props](/docs/components-and-props.html) for an introduction to props.
631631

632632
In particular, `this.props.children` is a special prop, typically defined by the child tags in the JSX expression rather than in the tag itself.
633633

0 commit comments

Comments
 (0)