Skip to content

Commit c473de7

Browse files
authored
translate(reference): isValidElement (#683) (#715)
Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
1 parent 46bb302 commit c473de7

1 file changed

Lines changed: 41 additions & 34 deletions

File tree

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
22
title: isValidElement
3+
translationStatus: ai-draft
34
---
45

6+
<Note>
7+
8+
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+
512
<Intro>
613

7-
`isValidElement` checks whether a value is a React element.
14+
`isValidElement` ti permette di verificare se un valore è un elemento React.
815

916
```js
1017
const isElement = isValidElement(value)
@@ -20,68 +27,68 @@ const isElement = isValidElement(value)
2027

2128
### `isValidElement(value)` {/*isvalidelement*/}
2229

23-
Call `isValidElement(value)` to check whether `value` is a React element.
30+
Chiama `isValidElement(value)` per verificare se `value` è un elemento React.
2431

2532
```js
2633
import { isValidElement, createElement } from 'react';
2734

28-
//React elements
35+
//Elementi React
2936
console.log(isValidElement(<p />)); // true
3037
console.log(isValidElement(createElement('p'))); // true
3138

32-
//Not React elements
39+
//Non sono elementi React
3340
console.log(isValidElement(25)); // false
3441
console.log(isValidElement('Hello')); // false
3542
console.log(isValidElement({ age: 42 })); // false
3643
```
3744

38-
[See more examples below.](#usage)
45+
[Vedi altri esempi sotto.](#usage)
3946

4047
#### Parameters {/*parameters*/}
4148

42-
* `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.
4350

4451
#### Returns {/*returns*/}
4552

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`.
4754

4855
#### Caveats {/*caveats*/}
4956

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.
5158

5259
---
5360

5461
## Usage {/*usage*/}
5562

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*/}
5764

58-
Call `isValidElement` to check if some value is a *React element.*
65+
Chiama `isValidElement` per verificare se un valore è un *elemento React.*
5966

60-
React elements are:
67+
Gli elementi React sono:
6168

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)
70+
- Valori prodotti chiamando [`createElement`](/reference/react/createElement)
6471

65-
For React elements, `isValidElement` returns `true`:
72+
Per gli elementi React, `isValidElement` restituisce `true`:
6673

6774
```js
6875
import { isValidElement, createElement } from 'react';
6976

70-
// ✅ JSX tags are React elements
77+
//I tag JSX sono elementi React
7178
console.log(isValidElement(<p />)); // true
7279
console.log(isValidElement(<MyComponent />)); // true
7380

74-
//Values returned by createElement are React elements
81+
//I valori restituiti da createElement sono elementi React
7582
console.log(isValidElement(createElement('p'))); // true
7683
console.log(isValidElement(createElement(MyComponent))); // true
7784
```
7885

79-
Any other values, such as strings, numbers, or arbitrary objects and arrays, are not React elements.
86+
Qualsiasi altro valore, come stringhe, numeri o oggetti e array arbitrari, non è un elemento React.
8087

81-
For them, `isValidElement` returns `false`:
88+
Per questi, `isValidElement` restituisce `false`:
8289

8390
```js
84-
//These are *not* React elements
91+
//Questi *non* sono elementi React
8592
console.log(isValidElement(null)); // false
8693
console.log(isValidElement(25)); // false
8794
console.log(isValidElement('Hello')); // false
@@ -90,39 +97,39 @@ console.log(isValidElement([<div />, <div />])); // false
9097
console.log(isValidElement(MyComponent)); // false
9198
```
9299

93-
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.
94101

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.
96103

97104
<DeepDive>
98105

99-
#### React elements vs React nodes {/*react-elements-vs-react-nodes*/}
106+
#### Elementi React vs nodi React {/*react-elements-vs-react-nodes*/}
100107

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*:
102109

103110
```js
104111
function MyComponent() {
105-
// ... you can return any React node ...
112+
// ... puoi restituire qualsiasi nodo React ...
106113
}
107114
```
108115

109-
A React node can be:
116+
Un nodo React può essere:
110117

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')`
119+
- Un [portale](/reference/react-dom/createPortal) creato con [`createPortal`](/reference/react-dom/createPortal)
120+
- Una stringa
121+
- Un numero
122+
- `true`, `false`, `null` o `undefined` (che non vengono visualizzati)
123+
- Un array di altri nodi React
117124

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:
119126

120127
```js
121128
function MyComponent() {
122-
return 42; // It's ok to return a number from component
129+
return 42; // Va bene restituire un numero da un componente
123130
}
124131
```
125132

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.
127134

128135
</DeepDive>

0 commit comments

Comments
 (0)