Skip to content

Commit 0e4ea32

Browse files
committed
translate(reference): useDebugValue
Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
1 parent b865d09 commit 0e4ea32

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

src/content/reference/react/useDebugValue.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
22
title: useDebugValue
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/useDebugValue.md).
9+
10+
</Note>
11+
512
<Intro>
613

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)
815

916
```js
1017
useDebugValue(value, format?)
@@ -20,7 +27,7 @@ useDebugValue(value, format?)
2027
2128
### `useDebugValue(value, format?)` {/*usedebugvalue*/}
2229
23-
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:
2431
2532
```js
2633
import { useDebugValue } from 'react';
@@ -32,22 +39,22 @@ function useOnlineStatus() {
3239
}
3340
```
3441
35-
[See more examples below.](#usage)
42+
[Vedi altri esempi sotto.](#usage)
3643
3744
#### Parameters {/*parameters*/}
3845
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.
4148
4249
#### Returns {/*returns*/}
4350
44-
`useDebugValue` does not return anything.
51+
`useDebugValue` non restituisce nulla.
4552
4653
## Usage {/*usage*/}
4754
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*/}
4956
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)
5158
5259
```js [[1, 5, "isOnline ? 'Online' : 'Offline'"]]
5360
import { useDebugValue } from 'react';
@@ -59,11 +66,11 @@ function useOnlineStatus() {
5966
}
6067
```
6168
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:
6370
64-
![A screenshot of React DevTools showing the debug value](/images/docs/react-devtools-usedebugvalue.png)
71+
![Uno screenshot di React DevTools che mostra il valore di debug](/images/docs/react-devtools-usedebugvalue.png)
6572
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`).
6774
6875
<Sandpack>
6976
@@ -103,20 +110,20 @@ function subscribe(callback) {
103110
104111
<Note>
105112
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.
107114
108115
</Note>
109116
110117
---
111118
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*/}
113120
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`:
115122
116123
```js [[1, 1, "date", 18], [2, 1, "date.toDateString()"]]
117124
useDebugValue(date, date => date.toDateString());
118125
```
119126
120-
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.
121128
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

Comments
 (0)