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: docs/docs/06-transferring-props.it-IT.md
+47-57Lines changed: 47 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -27,16 +27,14 @@ Nel resto di questo tutorial vengono illustrate le best practices, usando JSX e
27
27
Nella maggior parte dei casi dovresti esplicitamente passare le proprietà. Ciò assicura che venga esposto soltanto un sottoinsieme dell'API interna, del cui funzionamento si è certi.
28
28
29
29
```javascript
30
-
var FancyCheckbox =React.createClass({
31
-
render:function() {
32
-
var fancyClass =this.props.checked?'FancyChecked':'FancyUnchecked';
Usa sempre il pattern di destrutturazione quando trasferisci altre proprietà sconosciute in `other`.
90
86
91
87
```javascript
92
-
var FancyCheckbox =React.createClass({
93
-
render:function() {
94
-
var fancyClass =this.props.checked?'FancyChecked':'FancyUnchecked';
95
-
// ANTI-PATTERN: `checked` sarebbe passato al componente interno
96
-
return (
97
-
<div {...this.props} className={fancyClass} />
98
-
);
99
-
}
100
-
});
88
+
functionFancyCheckbox(props) {
89
+
var fancyClass =props.checked?'FancyChecked':'FancyUnchecked';
90
+
// ANTI-PATTERN: `checked` sarebbe passato al componente interno
91
+
return (
92
+
<div {...props} className={fancyClass} />
93
+
);
94
+
}
101
95
```
102
96
103
97
## Consumare e Trasferire la Stessa Proprietà
104
98
105
99
Se il tuo componente desidera consumare una proprietà, ma anche passarla ad altri, puoi passarla esplicitamente mediante `checked={checked}`. Questo è preferibile a passare l'intero oggetto `this.props` dal momento che è più facile effettuarne il linting e il refactoring.
106
100
107
101
```javascript
108
-
var FancyCheckbox =React.createClass({
109
-
render:function() {
110
-
var { checked, title, ...other } =this.props;
111
-
var fancyClass = checked ?'FancyChecked':'FancyUnchecked';
112
-
var fancyTitle = checked ?'X '+ title :'O '+ title;
113
-
return (
114
-
<label>
115
-
<input {...other}
116
-
checked={checked}
117
-
className={fancyClass}
118
-
type="checkbox"
119
-
/>
120
-
{fancyTitle}
121
-
</label>
122
-
);
123
-
}
124
-
});
102
+
functionFancyCheckbox(props) {
103
+
var { checked, title, ...other } = props;
104
+
var fancyClass = checked ?'FancyChecked':'FancyUnchecked';
105
+
var fancyTitle = checked ?'X '+ title :'O '+ title;
106
+
return (
107
+
<label>
108
+
<input {...other}
109
+
checked={checked}
110
+
className={fancyClass}
111
+
type="checkbox"
112
+
/>
113
+
{fancyTitle}
114
+
</label>
115
+
);
116
+
}
125
117
```
126
118
127
119
> NOTA:
@@ -150,14 +142,12 @@ z; // { a: 3, b: 4 }
150
142
Se non usi JSX, puoi usare una libreria per ottenere il medesimo pattern. Underscore supporta `_.omit` per omettere delle proprietà ed `_.extend` per copiare le proprietà in un nuovo oggetto.
151
143
152
144
```javascript
153
-
var FancyCheckbox =React.createClass({
154
-
render:function() {
155
-
var checked =this.props.checked;
156
-
var other =_.omit(this.props, 'checked');
157
-
var fancyClass = checked ?'FancyChecked':'FancyUnchecked';
0 commit comments