Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/content/warnings/invalid-aria-prop.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
---
title: Invalid ARIA Prop Warning
title: Warning sulle props ARIA non valide
translationStatus: ai-draft
---

Il warning invalid-aria-prop appare quando provi a renderizzare un elemento del DOM con una aria-* prop che non esiste nella [specifica](https://www.w3.org/TR/wai-aria-1.1/#states_and_properties) Web Accessibility Initiative (WAI) Accessible Rich Internet Application (ARIA).
<Note>

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/warnings/invalid-aria-prop.md).

</Note>

Il warning invalid-aria-prop appare quando provi a renderizzare un elemento del DOM con una prop `aria-*` che non esiste nella [specifica](https://www.w3.org/TR/wai-aria-1.1/#states_and_properties) Web Accessibility Initiative (WAI) Accessible Rich Internet Application (ARIA).

1. Se pensi che la prop che stai usando sia valida, controlla attentamente eventuali errori di battitura. `aria-labelledby` e `aria-activedescendant` sono spesso scritte in modo scorretto.

2. Se hai scritto `aria-role`, probabilmente intendevi `role`.

3. Altrimenti, se stai utilizzando l'ultima versione di React DOM e verificato che stai usando un nome di proprietà valido presente nella lista della specifica ARIA, cortesemente [riporta un bug](https://github.com/react/react/issues/new/choose).
3. Altrimenti, se stai utilizzando l'ultima versione di React DOM e hai verificato che stai usando un nome di proprietà valido presente nella lista della specifica ARIA, cortesemente [riporta un bug](https://github.com/react/react/issues/new/choose).
95 changes: 51 additions & 44 deletions src/content/warnings/invalid-hook-call-warning.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
---
title: Rules of Hooks
title: Regole degli Hook
translationStatus: ai-draft
---

You are probably here because you got the following error message:
<Note>

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/warnings/invalid-hook-call-warning.md).

</Note>

Probabilmente sei qui perché hai ricevuto il seguente messaggio di errore:

<ConsoleBlock level="error">

Hooks can only be called inside the body of a function component.

</ConsoleBlock>

There are three common reasons you might be seeing it:
Ci sono tre motivi comuni per cui potresti vederlo:

1. You might be **breaking the Rules of Hooks**.
2. You might have **mismatching versions** of React and React DOM.
3. You might have **more than one copy of React** in the same app.
1. Potresti **violare le Regole degli Hook**.
2. Potresti avere **versioni non corrispondenti** di React e React DOM.
3. Potresti avere **più di una copia di React** nella stessa app.

Let's look at each of these cases.
Vediamo ciascuno di questi casi.

## Breaking Rules of Hooks {/*breaking-rules-of-hooks*/}
## Violare le Regole degli Hook {/*breaking-rules-of-hooks*/}

Functions whose names start with `use` are called [*Hooks*](/reference/react) in React.
Le funzioni il cui nome inizia con `use` sono chiamate [*Hook*](/reference/react) in React.

**Don’t call Hooks inside loops, conditions, or nested functions.** Instead, always use Hooks at the top level of your React function, before any early returns. You can only call Hooks while React is rendering a function component:
**Non chiamare gli Hook dentro loop, condizioni o funzioni annidate.** Usa invece sempre gli Hook al livello superiore della tua funzione React, prima di qualsiasi return anticipato. Puoi chiamare gli Hook solo mentre React sta renderizzando un componente funzione:

* ✅ Call them at the top level in the body of a [function component](/learn/your-first-component).
* ✅ Call them at the top level in the body of a [custom Hook](/learn/reusing-logic-with-custom-hooks).
* ✅ Chiamali al livello superiore nel corpo di un [componente funzione](/learn/your-first-component).
* ✅ Chiamali al livello superiore nel corpo di un [custom hook](/learn/reusing-logic-with-custom-hooks).

```js{2-3,8-9}
function Counter() {
// ✅ Good: top-level in a function component
// ✅ Corretto: livello superiore in un componente funzione
const [count, setCount] = useState(0);
// ...
}

function useWindowWidth() {
// ✅ Good: top-level in a custom Hook
// ✅ Corretto: livello superiore in un custom hook
const [width, setWidth] = useState(window.innerWidth);
// ...
}
```

It’s **not** supported to call Hooks (functions starting with `use`) in any other cases, for example:
**Non** è supportato chiamare gli Hook (funzioni che iniziano con `use`) in nessun altro caso, ad esempio:

* 🔴 Do not call Hooks inside conditions or loops.
* 🔴 Do not call Hooks after a conditional `return` statement.
* 🔴 Do not call Hooks in event handlers.
* 🔴 Do not call Hooks in class components.
* 🔴 Do not call Hooks inside functions passed to `useMemo`, `useReducer`, or `useEffect`.
* 🔴 Non chiamare gli Hook dentro condizioni o loop.
* 🔴 Non chiamare gli Hook dopo un'istruzione `return` condizionale.
* 🔴 Non chiamare gli Hook nei gestori di eventi.
* 🔴 Non chiamare gli Hook nei componenti classe.
* 🔴 Non chiamare gli Hook dentro funzioni passate a `useMemo`, `useReducer` o `useEffect`.

If you break these rules, you might see this error.
Se violi queste regole, potresti vedere questo errore.

```js{3-4,11-12,20-21}
function Bad({ cond }) {
if (cond) {
// 🔴 Bad: inside a condition (to fix, move it outside!)
// 🔴 Sbagliato: dentro una condizione (per correggere, spostalo fuori!)
const theme = useContext(ThemeContext);
}
// ...
}

function Bad() {
for (let i = 0; i < 10; i++) {
// 🔴 Bad: inside a loop (to fix, move it outside!)
// 🔴 Sbagliato: dentro un loop (per correggere, spostalo fuori!)
const theme = useContext(ThemeContext);
}
// ...
Expand All @@ -72,22 +79,22 @@ function Bad({ cond }) {
if (cond) {
return;
}
// 🔴 Bad: after a conditional return (to fix, move it before the return!)
// 🔴 Sbagliato: dopo un return condizionale (per correggere, spostalo prima del return!)
const theme = useContext(ThemeContext);
// ...
}

function Bad() {
function handleClick() {
// 🔴 Bad: inside an event handler (to fix, move it outside!)
// 🔴 Sbagliato: dentro un gestore di eventi (per correggere, spostalo fuori!)
const theme = useContext(ThemeContext);
}
// ...
}

function Bad() {
const style = useMemo(() => {
// 🔴 Bad: inside useMemo (to fix, move it outside!)
// 🔴 Sbagliato: dentro useMemo (per correggere, spostalo fuori!)
const theme = useContext(ThemeContext);
return createStyle(theme);
});
Expand All @@ -96,63 +103,63 @@ function Bad() {

class Bad extends React.Component {
render() {
// 🔴 Bad: inside a class component (to fix, write a function component instead of a class!)
// 🔴 Sbagliato: dentro componenti classe (per correggere, scrivi un componente funzione al posto di una classe!)
useEffect(() => {})
// ...
}
}
```

You can use the [`eslint-plugin-react-hooks` plugin](https://www.npmjs.com/package/eslint-plugin-react-hooks) to catch these mistakes.
Puoi usare il plugin [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) per individuare questi errori.

<Note>

[Custom Hooks](/learn/reusing-logic-with-custom-hooks) *may* call other Hooks (that's their whole purpose). This works because custom Hooks are also supposed to only be called while a function component is rendering.
I [custom hook](/learn/reusing-logic-with-custom-hooks) *possono* chiamare altri Hook (è proprio il loro scopo). Funziona perché anche i custom hook dovrebbero essere chiamati solo mentre un componente funzione viene renderizzato.

</Note>

## Mismatching Versions of React and React DOM {/*mismatching-versions-of-react-and-react-dom*/}
## Versioni non corrispondenti di React e React DOM {/*mismatching-versions-of-react-and-react-dom*/}

You might be using a version of `react-dom` (< 16.8.0) or `react-native` (< 0.59) that doesn't yet support Hooks. You can run `npm ls react-dom` or `npm ls react-native` in your application folder to check which version you're using. If you find more than one of them, this might also create problems (more on that below).
Potresti usare una versione di `react-dom` (< 16.8.0) o `react-native` (< 0.59) che non supporta ancora gli Hook. Puoi eseguire `npm ls react-dom` o `npm ls react-native` nella cartella della tua applicazione per verificare quale versione stai usando. Se ne trovi più di una, questo potrebbe creare problemi (ne parliamo di più sotto).

## Duplicate React {/*duplicate-react*/}
## React duplicato {/*duplicate-react*/}

In order for Hooks to work, the `react` import from your application code needs to resolve to the same module as the `react` import from inside the `react-dom` package.
Affinché gli Hook funzionino, l'import di `react` dal codice della tua applicazione deve risolvere lo stesso modulo dell'import di `react` dall'interno del pacchetto `react-dom`.

If these `react` imports resolve to two different exports objects, you will see this warning. This may happen if you **accidentally end up with two copies** of the `react` package.
Se questi import di `react` risolvono due oggetti export diversi, vedrai questo warning. Questo può succedere se **finisci accidentalmente con due copie** del pacchetto `react`.

If you use Node for package management, you can run this check in your project folder:
Se usi Node per la gestione dei pacchetti, puoi eseguire questo controllo nella cartella del tuo progetto:

<TerminalBlock>

npm ls react

</TerminalBlock>

If you see more than one React, you'll need to figure out why this happens and fix your dependency tree. For example, maybe a library you're using incorrectly specifies `react` as a dependency (rather than a peer dependency). Until that library is fixed, [Yarn resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) is one possible workaround.
Se vedi più di un React, dovrai capire perché succede e correggere l'albero delle dipendenze. Ad esempio, forse una libreria che usi specifica `react` in modo errato come dipendenza (invece che come peer dependency). Finché quella libreria non viene corretta, le [Yarn resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) sono una possibile soluzione temporanea.

You can also try to debug this problem by adding some logs and restarting your development server:
Puoi anche provare a debuggare questo problema aggiungendo alcuni log e riavviando il server di sviluppo:

```js
// Add this in node_modules/react-dom/index.js
// Aggiungi questo in node_modules/react-dom/index.js
window.React1 = require('react');

// Add this in your component file
// Aggiungi questo nel file del tuo componente
require('react-dom');
window.React2 = require('react');
console.log(window.React1 === window.React2);
```

If it prints `false` then you might have two Reacts and need to figure out why that happened. [This issue](https://github.com/react/react/issues/13991) includes some common reasons encountered by the community.
Se stampa `false`, potresti avere due React e devi capire perché è successo. [Questa issue](https://github.com/react/react/issues/13991) include alcuni motivi comuni riscontrati dalla community.

This problem can also come up when you use `npm link` or an equivalent. In that case, your bundler might "see" two Reactsone in application folder and one in your library folder. Assuming `myapp` and `mylib` are sibling folders, one possible fix is to run `npm link ../myapp/node_modules/react` from `mylib`. This should make the library use the application's React copy.
Questo problema può presentarsi anche quando usi `npm link` o un equivalente. In quel caso, il tuo bundler potrebbe "vedere" due Reactuno nella cartella dell'applicazione e uno nella cartella della tua libreria. Supponendo che `myapp` e `mylib` siano cartelle sorelle, una possibile correzione è eseguire `npm link ../myapp/node_modules/react` da `mylib`. In questo modo la libreria userà la copia di React dell'applicazione.

<Note>

In general, React supports using multiple independent copies on one page (for example, if an app and a third-party widget both use it). It only breaks if `require('react')` resolves differently between the component and the `react-dom` copy it was rendered with.
In generale, React supporta l'uso di più copie indipendenti nella stessa pagina (ad esempio, se un'app e un widget di terze parti lo usano entrambi). Si rompe solo se `require('react')` risolve in modo diverso tra il componente e la copia di `react-dom` con cui è stato renderizzato.

</Note>

## Other Causes {/*other-causes*/}
## Altre cause {/*other-causes*/}

If none of this worked, please comment in [this issue](https://github.com/react/react/issues/13991) and we'll try to help. Try to create a small reproducing exampleyou might discover the problem as you're doing it.
Se niente di tutto ciò ha funzionato, commenta in [questa issue](https://github.com/react/react/issues/13991) e cercheremo di aiutarti. Prova a creare un piccolo esempio riproducibilepotresti scoprire il problema mentre lo fai.
37 changes: 22 additions & 15 deletions src/content/warnings/react-dom-test-utils.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
---
title: react-dom/test-utils Deprecation Warnings
title: Warning di deprecazione react-dom/test-utils
translationStatus: ai-draft
---

<Note>

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/warnings/react-dom-test-utils.md).

</Note>

## ReactDOMTestUtils.act() warning {/*reactdomtestutilsact-warning*/}

`act` from `react-dom/test-utils` has been deprecated in favor of `act` from `react`.
`act` da `react-dom/test-utils` è deprecato in favore di `act` da `react`.

Before:
Prima:

```js
import {act} from 'react-dom/test-utils';
```

After:
Dopo:

```js
import {act} from 'react';
```

## Rest of ReactDOMTestUtils APIS {/*rest-of-reactdomtestutils-apis*/}
## Resto delle API ReactDOMTestUtils {/*rest-of-reactdomtestutils-apis*/}

All APIs except `act` have been removed.
Tutte le API tranne `act` sono state rimosse.

The React Team recommends migrating your tests to [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) for a modern and well supported testing experience.
Il team React consiglia di migrare i tuoi test a [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) per un'esperienza di testing moderna e ben supportata.

### ReactDOMTestUtils.renderIntoDocument {/*reactdomtestutilsrenderintodocument*/}

`renderIntoDocument` can be replaced with `render` from `@testing-library/react`.
`renderIntoDocument` può essere sostituito con `render` da `@testing-library/react`.

Before:
Prima:

```js
import {renderIntoDocument} from 'react-dom/test-utils';

renderIntoDocument(<Component />);
```

After:
Dopo:

```js
import {render} from '@testing-library/react';
Expand All @@ -46,9 +53,9 @@ render(<Component />);

### ReactDOMTestUtils.Simulate {/*reactdomtestutilssimulate*/}

`Simulate` can be replaced with `fireEvent` from `@testing-library/react`.
`Simulate` può essere sostituito con `fireEvent` da `@testing-library/react`.

Before:
Prima:

```js
import {Simulate} from 'react-dom/test-utils';
Expand All @@ -57,7 +64,7 @@ const element = document.querySelector('button');
Simulate.click(element);
```

After:
Dopo:

```js
import {fireEvent} from '@testing-library/react';
Expand All @@ -66,9 +73,9 @@ const element = document.querySelector('button');
fireEvent.click(element);
```

Be aware that `fireEvent` dispatches an actual event on the element and doesn't just synthetically call the event handler.
Tieni presente che `fireEvent` invia un evento reale sull'elemento e non chiama solo sinteticamente il gestore di eventi.

### List of all removed APIs {/*list-of-all-removed-apis-list-of-all-removed-apis*/}
### Elenco di tutte le API rimosse {/*list-of-all-removed-apis-list-of-all-removed-apis*/}

- `mockComponent()`
- `isElement()`
Expand Down
15 changes: 11 additions & 4 deletions src/content/warnings/react-test-renderer.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
---
title: react-test-renderer Deprecation Warnings
title: Warning di deprecazione react-test-renderer
translationStatus: ai-draft
---

<Note>

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/warnings/react-test-renderer.md).

</Note>

## ReactTestRenderer.create() warning {/*reacttestrenderercreate-warning*/}

react-test-renderer is deprecated. A warning will fire whenever calling ReactTestRenderer.create() or ReactShallowRender.render(). The react-test-renderer package will remain available on NPM but will not be maintained and may break with new React features or changes to React's internals.
react-test-renderer è deprecato. Un warning viene mostrato ogni volta che chiami `ReactTestRenderer.create()` o `ReactShallowRender.render()`. Il pacchetto react-test-renderer resterà disponibile su NPM ma non sarà mantenuto e potrebbe rompersi con nuove funzionalità di React o modifiche agli internals di React.

The React Team recommends migrating your tests to [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) or [@testing-library/react-native](https://callstack.github.io/react-native-testing-library/docs/start/intro) for a modern and well supported testing experience.
Il team React consiglia di migrare i tuoi test a [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) o [@testing-library/react-native](https://callstack.github.io/react-native-testing-library/docs/start/intro) per un'esperienza di testing moderna e ben supportata.


## new ShallowRenderer() warning {/*new-shallowrenderer-warning*/}

The react-test-renderer package no longer exports a shallow renderer at `react-test-renderer/shallow`. This was simply a repackaging of a previously extracted separate package: `react-shallow-renderer`. Therefore you can continue using the shallow renderer in the same way by installing it directly. See [Github](https://github.com/enzymejs/react-shallow-renderer) / [NPM](https://www.npmjs.com/package/react-shallow-renderer).
Il pacchetto react-test-renderer non esporta più uno shallow renderer in `react-test-renderer/shallow`. Era semplicemente un reimpacchettamento di un pacchetto separato estratto in precedenza: `react-shallow-renderer`. Puoi quindi continuare a usare lo shallow renderer nello stesso modo installandolo direttamente. Vedi [Github](https://github.com/enzymejs/react-shallow-renderer) / [NPM](https://www.npmjs.com/package/react-shallow-renderer).
Loading
Loading