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
Questa pagina è stata tradotta automaticamente e supervisionata da un maintainer. Un'ulteriore revisione da parte della community sarebbe comunque utile. [Migliora questa traduzione](https://github.com/reactjs/it.react.dev/edit/main/src/content/reference/react/isValidElement.md).
9
+
10
+
</Note>
11
+
5
12
<Intro>
6
13
7
-
`isValidElement`checks whether a value is a React element.
14
+
`isValidElement`ti permette di verificare se un valore è un elemento React.
*`value`: The `value` you want to check. It can be any a value of any type.
49
+
*`value`: Il valore che vuoi verificare. Può essere di qualsiasi tipo.
43
50
44
51
#### Returns {/*returns*/}
45
52
46
-
`isValidElement`returns`true`if the `value`is a React element. Otherwise, it returns`false`.
53
+
`isValidElement`restituisce`true`se `value`è un elemento React. Altrimenti, restituisce`false`.
47
54
48
55
#### Caveats {/*caveats*/}
49
56
50
-
***Only [JSX tags](/learn/writing-markup-with-jsx)and objects returned by [`createElement`](/reference/react/createElement)are considered to be React elements.**For example, even though a number like`42`is a valid React*node* (and can be returned from a component), it is not a valid React element. Arrays and portals created with [`createPortal`](/reference/react-dom/createPortal)are also *not* considered to be React elements.
57
+
***Solo i [tag JSX](/learn/writing-markup-with-jsx)e gli oggetti restituiti da [`createElement`](/reference/react/createElement)sono considerati elementi React.**Ad esempio, anche se un numero come`42`è un *nodo React* valido (e può essere restituito da un componente), non è un elemento React valido. Anche gli array e i [portali](/reference/react-dom/createPortal) creati con [`createPortal`](/reference/react-dom/createPortal)*non* sono considerati elementi React.
51
58
52
59
---
53
60
54
61
## Usage {/*usage*/}
55
62
56
-
### Checking if something is a React element {/*checking-if-something-is-a-react-element*/}
63
+
### Verificare se qualcosa è un elemento React {/*checking-if-something-is-a-react-element*/}
57
64
58
-
Call`isValidElement`to check if some value is a *React element.*
65
+
Chiama`isValidElement`per verificare se un valore è un *elemento React.*
59
66
60
-
React elements are:
67
+
Gli elementi React sono:
61
68
62
-
-Values produced by writing a [JSX tag](/learn/writing-markup-with-jsx)
63
-
-Values produced by calling[`createElement`](/reference/react/createElement)
69
+
-Valori prodotti scrivendo un [tag JSX](/learn/writing-markup-with-jsx)
It is very uncommon to need`isValidElement`. It's mostly useful if you're calling another API that *only* accepts elements (like [`cloneElement`](/reference/react/cloneElement) does) and you want to avoid an error when your argument is not a React element.
100
+
È molto raro aver bisogno di`isValidElement`. È soprattutto utile se stai chiamando un'altra API che accetta *solo* elementi (come fa [`cloneElement`](/reference/react/cloneElement)) e vuoi evitare un errore quando il tuo argomento non è un elemento React.
94
101
95
-
Unless you have some very specific reason to add an `isValidElement` check, you probably don't need it.
102
+
A meno che tu non abbia un motivo molto specifico per aggiungere un controllo con `isValidElement`, probabilmente non ne hai bisogno.
96
103
97
104
<DeepDive>
98
105
99
-
#### React elements vs React nodes {/*react-elements-vs-react-nodes*/}
106
+
#### Elementi React vs nodi React {/*react-elements-vs-react-nodes*/}
100
107
101
-
When you write a component, you can return any kind of *React node* from it:
108
+
Quando scrivi un componente, puoi restituire qualsiasi tipo di *nodo React*:
102
109
103
110
```js
104
111
functionMyComponent() {
105
-
// ... you can return any React node ...
112
+
// ... puoi restituire qualsiasi nodo React ...
106
113
}
107
114
```
108
115
109
-
A React node can be:
116
+
Un nodo React può essere:
110
117
111
-
-A React element created like `<div />`or`createElement('div')`
112
-
-A portal created with[`createPortal`](/reference/react-dom/createPortal)
113
-
-A string
114
-
-A number
115
-
-`true`, `false`, `null`, or`undefined` (which are not displayed)
116
-
-An array of other React nodes
118
+
-Un elemento React creato come `<div />`o`createElement('div')`
-`true`, `false`, `null` o`undefined` (che non vengono visualizzati)
123
+
-Un array di altri nodi React
117
124
118
-
**Note`isValidElement`checks whether the argument is a *React element,*not whether it's a React node.**For example, `42`is not a valid React element. However, it is a perfectly valid React node:
125
+
**Nota`isValidElement`verifica se l'argomento è un *elemento React,*non se è un nodo React.**Ad esempio, `42`non è un elemento React valido. Tuttavia, è un nodo React perfettamente valido:
119
126
120
127
```js
121
128
functionMyComponent() {
122
-
return42; //It's ok to return a number from component
129
+
return42; //Va bene restituire un numero da un componente
123
130
}
124
131
```
125
132
126
-
This is why you shouldn't use `isValidElement`as a way to check whether something can be rendered.
133
+
Per questo non dovresti usare `isValidElement`per verificare se qualcosa può essere renderizzato.
0 commit comments