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: src/content/reference/react/useDebugValue.md
+23-16Lines changed: 23 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,17 @@
1
1
---
2
2
title: useDebugValue
3
+
translationStatus: ai-draft
3
4
---
4
5
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/useDebugValue.md).
9
+
10
+
</Note>
11
+
5
12
<Intro>
6
13
7
-
`useDebugValue`is a React Hook that lets you add a label to a custom Hook in [React DevTools.](/learn/react-developer-tools)
14
+
`useDebugValue`è un Hook React che ti permette di aggiungere un'etichetta a un custom Hook in [React DevTools.](/learn/react-developer-tools)
Call`useDebugValue`at the top level of your [custom Hook](/learn/reusing-logic-with-custom-hooks) to display a readable debug value:
30
+
Chiama`useDebugValue`al top level del tuo [custom Hook](/learn/reusing-logic-with-custom-hooks) per visualizzare un valore di debug leggibile:
24
31
25
32
```js
26
33
import { useDebugValue } from'react';
@@ -32,22 +39,22 @@ function useOnlineStatus() {
32
39
}
33
40
```
34
41
35
-
[See more examples below.](#usage)
42
+
[Vedi altri esempi sotto.](#usage)
36
43
37
44
#### Parameters {/*parameters*/}
38
45
39
-
* `value`: The value you want to display in React DevTools. It can have any type.
40
-
* **optional** `format`: A formatting function. When the component is inspected, React DevTools will call the formatting function with the `value`as the argument, and then display the returned formatted value (which may have any type). If you don't specify the formatting function, the original `value`itself will be displayed.
46
+
* `value`: Il valore che vuoi visualizzare in React DevTools. Può essere di qualsiasi tipo.
47
+
* **optional** `format`: Una funzione di formattazione. Quando il componente viene ispezionato, React DevTools chiamerà la funzione di formattazione con `value`come argomento, e poi visualizzerà il valore formattato restituito (che può essere di qualsiasi tipo). Se non specifichi la funzione di formattazione, verrà visualizzato il `value`originale.
41
48
42
49
#### Returns {/*returns*/}
43
50
44
-
`useDebugValue`does not return anything.
51
+
`useDebugValue`non restituisce nulla.
45
52
46
53
## Usage {/*usage*/}
47
54
48
-
### Adding a label to a custom Hook {/*adding-a-label-to-a-custom-hook*/}
55
+
### Aggiungere un'etichetta a un custom Hook {/*adding-a-label-to-a-custom-hook*/}
49
56
50
-
Call`useDebugValue`at the top level of your [custom Hook](/learn/reusing-logic-with-custom-hooks) to display a readable <CodeStep step={1}>debug value</CodeStep> for [React DevTools.](/learn/react-developer-tools)
57
+
Chiama`useDebugValue`al top level del tuo [custom Hook](/learn/reusing-logic-with-custom-hooks) per visualizzare un <CodeStep step={1}>valore di debug</CodeStep> leggibile per [React DevTools.](/learn/react-developer-tools)
51
58
52
59
```js [[1, 5, "isOnline ? 'Online' : 'Offline'"]]
53
60
import { useDebugValue } from'react';
@@ -59,11 +66,11 @@ function useOnlineStatus() {
59
66
}
60
67
```
61
68
62
-
This gives components calling `useOnlineStatus`a label like `OnlineStatus:"Online"`when you inspect them:
69
+
Questo fornisce ai componenti che chiamano `useOnlineStatus`un'etichetta come `OnlineStatus:"Online"`quando li ispezioni:
63
70
64
-

71
+

65
72
66
-
Without the `useDebugValue` call, only the underlying data (in this example, `true`) would be displayed.
73
+
Senza la chiamata a `useDebugValue`, verrebbero visualizzati solo i dati sottostanti (in questo esempio, `true`).
67
74
68
75
<Sandpack>
69
76
@@ -103,20 +110,20 @@ function subscribe(callback) {
103
110
104
111
<Note>
105
112
106
-
Don't add debug values to every custom Hook. It's most valuable for custom Hooks that are part of shared libraries and that have a complex internal data structure that's difficult to inspect.
113
+
Non aggiungere valori di debug a ogni custom Hook. È più utile per i custom Hook che fanno parte di librerie condivise e che hanno una struttura dati interna complessa difficile da ispezionare.
107
114
108
115
</Note>
109
116
110
117
---
111
118
112
-
### Deferring formatting of a debug value {/*deferring-formatting-of-a-debug-value*/}
119
+
### Posticipare la formattazione di un valore di debug {/*deferring-formatting-of-a-debug-value*/}
113
120
114
-
You can also pass a formatting function as the second argument to`useDebugValue`:
121
+
Puoi anche passare una funzione di formattazione come secondo argomento a`useDebugValue`:
Your formatting function will receive the <CodeStep step={1}>debug value</CodeStep> as a parameter and should return a <CodeStep step={2}>formatted display value</CodeStep>. When your component is inspected, React DevTools will call this function and display its result.
127
+
La tua funzione di formattazione riceverà il <CodeStep step={1}>valore di debug</CodeStep> come parametro e dovrebbe restituire un <CodeStep step={2}>valore di visualizzazione formattato</CodeStep>. Quando il tuo componente viene ispezionato, React DevTools chiamerà questa funzione e visualizzerà il suo risultato.
121
128
122
-
This lets you avoid running potentially expensive formatting logic unless the component is actually inspected. For example, if`date`is a Date value, this avoids calling `toDateString()`on it for every render.
129
+
Questo ti permette di evitare di eseguire una logica di formattazione potenzialmente costosa a meno che il componente non venga effettivamente ispezionato. Ad esempio, se`date`è un valore Date, questo evita di chiamare `toDateString()`su di esso per ogni renderizzazione.
0 commit comments