# General Translation Changelog: gt-react 10.16.0: Stringhe localizzate di tempo relativo
URL: https://generaltranslation.com/it/blog/gt-react_v10_16_0.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 
Authors: Ernest McCarter
Published: 2026-04-01

## Panoramica

Nuovo componente variabile [`<RelativeTime>`](/docs/react/reference/components/relative-time) per eseguire il rendering di stringhe di tempo relativo localizzate, come &quot;2 ore fa&quot; o &quot;tra 3 giorni&quot;. Usa [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat) internamente.

| Pacchetto            | Versione |
| -------------------- | -------- |
| `gt-react`           | 10.16.0  |
| `gt-next`            | 6.15.0   |
| `generaltranslation` | 8.2.0    |

## Utilizzo

### Seleziona automaticamente l&#39;unità da un oggetto Date

Passa un oggetto `Date` e il componente seleziona automaticamente l&#39;unità più adatta:

```jsx
import { RelativeTime } from "gt-react";

<RelativeTime>{post.createdAt}</RelativeTime>
// "2 ore fa", "tra 3 giorni", ecc.
```


### Valore e unità espliciti

Specifica un valore e un&#39;unità precisi, come nell&#39;API `Intl.RelativeTimeFormat`:

```jsx
import { RelativeTime } from "gt-react";

<RelativeTime value={3} unit="day" />
// "tra 3 giorni"
```


### Nelle traduzioni

Racchiudi [`<RelativeTime>`](/docs/react/reference/components/relative-time) in [`<T>`](/docs/react/reference/components/t) per includerlo nelle frasi tradotte:

```jsx
import { T, RelativeTime } from "gt-react";

<T id="commentPosted">
  Posted <RelativeTime>{comment.createdAt}</RelativeTime>
</T>
```

## Sicurezza in fase di idratazione

[`<RelativeTime>`](/docs/react/reference/components/relative-time) calcola il tempo relativo localmente, il che può causare errori di idratazione nelle app con rendering lato server. Per evitarli, fissa `baseDate`:

```jsx
const now = new Date();

<RelativeTime baseDate={now}>{post.createdAt}</RelativeTime>
```

## Utilità principali

Sono disponibili anche due nuove funzioni di formattazione in `generaltranslation`:

* `formatRelativeTimeFromDate(date, options)` — funzione autonoma
* `GT.formatRelativeTimeFromDate(date, options)` — metodo della classe

## Link

* [`<RelativeTime>` riferimento API](/docs/react/reference/components/relative-time)
* [Uso dei componenti variabili](/docs/react/guides/formatting-variables)
* [PR #1153](https://github.com/generaltranslation/gt/pull/1153)

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
