Skip to content

Commit efed1d3

Browse files
authored
Translate managing-state (#450)
1 parent 64782a9 commit efed1d3

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

src/content/learn/managing-state.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
---
2-
title: Managing State
2+
title: Gestione dello state
33
---
44

55
<Intro>
66

7-
As your application grows, it helps to be more intentional about how your state is organized and how the data flows between your components. Redundant or duplicate state is a common source of bugs. In this chapter, you'll learn how to structure your state well, how to keep your state update logic maintainable, and how to share state between distant components.
7+
Man mano che la tua applicazione cresce, è utile essere più intenzionali su come viene organizzato il tuo state e come i dati fluiscono tra i tuoi componenti. Lo state ridondante o duplicato è una fonte comune di bug. In questo capitolo, imparerai come strutturare bene il tuo state, come mantenere la logica di aggiornamento dello state manutenibile e come condividere lo state tra componenti distanti.
88

99
</Intro>
1010

1111
<YouWillLearn isChapter={true}>
1212

13-
* [How to think about UI changes as state changes](/learn/reacting-to-input-with-state)
14-
* [How to structure state well](/learn/choosing-the-state-structure)
15-
* [How to "lift state up" to share it between components](/learn/sharing-state-between-components)
16-
* [How to control whether the state gets preserved or reset](/learn/preserving-and-resetting-state)
17-
* [How to consolidate complex state logic in a function](/learn/extracting-state-logic-into-a-reducer)
18-
* [How to pass information without "prop drilling"](/learn/passing-data-deeply-with-context)
19-
* [How to scale state management as your app grows](/learn/scaling-up-with-reducer-and-context)
13+
* [Come pensare ai cambiamenti della UI come cambiamenti dello state](/learn/reacting-to-input-with-state)
14+
* [Come strutturare bene lo state](/learn/choosing-the-state-structure)
15+
* [Come "alzare lo state" per condividerlo tra i componenti](/learn/sharing-state-between-components)
16+
* [Come controllare se lo state viene preservato o ripristinato](/learn/preserving-and-resetting-state)
17+
* [Come consolidare la logica complessa dello state in una funzione](/learn/extracting-state-logic-into-a-reducer)
18+
* [Come passare informazioni senza "prop drilling"](/learn/passing-data-deeply-with-context)
19+
* [Come scalare la gestione dello state man mano che l'applicazione cresce](/learn/scaling-up-with-reducer-and-context)
2020

2121
</YouWillLearn>
2222

23-
## Reacting to input with state {/*reacting-to-input-with-state*/}
23+
## Reagire all'input con lo state {/*reacting-to-input-with-state*/}
2424

25-
With React, you won't modify the UI from code directly. For example, you won't write commands like "disable the button", "enable the button", "show the success message", etc. Instead, you will describe the UI you want to see for the different visual states of your component ("initial state", "typing state", "success state"), and then trigger the state changes in response to user input. This is similar to how designers think about UI.
25+
Con React, non modificherai direttamente l'interfaccia utente dal codice. Ad esempio, non scriverai comandi come "disabilita il pulsante", "abilita il pulsante", "mostra il messaggio di successo", ecc. Invece, descriverai l'interfaccia utente che desideri vedere per i diversi stati visivi del tuo componente ("state iniziale", "state di digitazione", "state di successo") e quindi attiverai i cambiamenti di state in risposta all'input dell'utente. Questo è simile al modo in cui i designer pensano all'interfaccia utente.
2626

27-
Here is a quiz form built using React. Note how it uses the `status` state variable to determine whether to enable or disable the submit button, and whether to show the success message instead.
27+
Ecco un modulo di quiz costruito con React. Nota come utilizza la variabile di state `status` per determinare se abilitare o disabilitare il pulsante di invio e se mostrare invece il messaggio di successo.
2828

2929
<Sandpack>
3030

@@ -108,15 +108,15 @@ function submitForm(answer) {
108108
109109
<LearnMore path="/learn/reacting-to-input-with-state">
110110
111-
Read **[Reacting to Input with State](/learn/reacting-to-input-with-state)** to learn how to approach interactions with a state-driven mindset.
111+
Leggi **[Reagire all'input con lo state](/learn/reacting-to-input-with-state)** per imparare come affrontare le interazioni con una mentalità basata sullo state.
112112
113113
</LearnMore>
114114
115-
## Choosing the state structure {/*choosing-the-state-structure*/}
115+
## Scelta della struttura dello state {/*choosing-the-state-structure*/}
116116
117-
Structuring state well can make a difference between a component that is pleasant to modify and debug, and one that is a constant source of bugs. The most important principle is that state shouldn't contain redundant or duplicated information. If there's unnecessary state, it's easy to forget to update it, and introduce bugs!
117+
Strutturare bene lo state può fare la differenza tra un componente piacevole da modificare e debuggare e uno che è una fonte costante di bug. Il principio più importante è che lo state non dovrebbe contenere informazioni ridondanti o duplicate. Se c'è state non necessario, è facile dimenticarsi di aggiornarlo e introdurre bug!
118118
119-
For example, this form has a **redundant** `fullName` state variable:
119+
Ad esempio, questo modulo ha una variabile di state `fullName` **ridondante** :
120120
121121
<Sandpack>
122122
@@ -169,7 +169,7 @@ label { display: block; margin-bottom: 5px; }
169169
170170
</Sandpack>
171171
172-
You can remove it and simplify the code by calculating `fullName` while the component is rendering:
172+
Puoi rimuoverla e semplificare il codice calcolando `fullName` durante il rendering del componente:
173173
174174
<Sandpack>
175175
@@ -221,19 +221,19 @@ label { display: block; margin-bottom: 5px; }
221221
222222
</Sandpack>
223223
224-
This might seem like a small change, but many bugs in React apps are fixed this way.
224+
Questo potrebbe essere un cambiamento di poco conto, ma molti bug nella applicazioni React vengono risolti in questo modo.
225225
226226
<LearnMore path="/learn/choosing-the-state-structure">
227227
228-
Read **[Choosing the State Structure](/learn/choosing-the-state-structure)** to learn how to design the state shape to avoid bugs.
228+
Leggi **[Scegliere la struttura dello state](/learn/choosing-the-state-structure)** per imparare come progettare la forma dello state per evitare bug.
229229
230230
</LearnMore>
231231
232-
## Sharing state between components {/*sharing-state-between-components*/}
232+
## Condivisione dello state tra i componenti {/*sharing-state-between-components*/}
233233
234-
Sometimes, you want the state of two components to always change together. To do it, remove state from both of them, move it to their closest common parent, and then pass it down to them via props. This is known as "lifting state up", and it's one of the most common things you will do writing React code.
234+
A volte, desideri che lo state di due componenti cambi sempre insieme. Per farlo, rimuovi lo state da entrambi i componenti, spostalo al loro genitore comune più vicino e quindi passalo loro tramite le props. Questo è noto come "alzare lo state" ed è una delle cose più comuni che farai scrivendo codice React.
235235
236-
In this example, only one panel should be active at a time. To achieve this, instead of keeping the active state inside each individual panel, the parent component holds the state and specifies the props for its children.
236+
In questo esempio, solo un pannello dovrebbe essere attivo alla volta. Per ottenere questo risultato, anziché mantenere lo state attivo all'interno di ciascun pannello individuale, il componente genitore tiene traccia dello state e specifica le props per i suoi figli.
237237
238238
<Sandpack>
239239
@@ -296,15 +296,15 @@ h3, p { margin: 5px 0px; }
296296
297297
<LearnMore path="/learn/sharing-state-between-components">
298298
299-
Read **[Sharing State Between Components](/learn/sharing-state-between-components)** to learn how to lift state up and keep components in sync.
299+
Leggi **[Condivisione dello State tra i Componenti](/learn/sharing-state-between-components)** per imparare come alzare lo state e mantenere i componenti sincronizzati.
300300
301301
</LearnMore>
302302
303-
## Preserving and resetting state {/*preserving-and-resetting-state*/}
303+
## Preservazione e ripristino dello state {/*preserving-and-resetting-state*/}
304304
305-
When you re-render a component, React needs to decide which parts of the tree to keep (and update), and which parts to discard or re-create from scratch. In most cases, React's automatic behavior works well enough. By default, React preserves the parts of the tree that "match up" with the previously rendered component tree.
305+
Quando si ridisegna un componente, React deve decidere quali parti dell'albero mantenere (e aggiornare) e quali parti scartare o ricreare da zero. Nella maggior parte dei casi, il comportamento automatico di React funziona abbastanza bene. Per impostazione predefinita, React conserva le parti dell'albero che "corrispondono" all'albero dei componenti precedentemente renderizzato.
306306

307-
However, sometimes this is not what you want. In this chat app, typing a message and then switching the recipient does not reset the input. This can make the user accidentally send a message to the wrong person:
307+
Tuttavia, a volte questo non è ciò che si desidera. In questa chat app, digitare un messaggio e quindi passare a un altro destinatario non resetta l'input. Ciò può portare l'utente a inviare accidentalmente un messaggio alla persona sbagliata:
308308

309309
<Sandpack>
310310

@@ -399,7 +399,7 @@ textarea {
399399

400400
</Sandpack>
401401

402-
React lets you override the default behavior, and *force* a component to reset its state by passing it a different `key`, like `<Chat key={email} />`. This tells React that if the recipient is different, it should be considered a *different* `Chat` component that needs to be re-created from scratch with the new data (and UI like inputs). Now switching between the recipients resets the input field--even though you render the same component.
402+
React ti consente di sovrascrivere il comportamento predefinito e *forzare* un componente a ripristinare il suo state passando una `key`, diversa, ad esempio `<Chat key={email} />`. Ciò indica a React che, se il destinatario è *diverso*, il componente `Chat` deve essere considerato un componente diverso e che deve essere ricreato da zero con i nuovi dati (e l'interfaccia utente come gli input). Ora, passando da un destinatario all'altro, l'input viene ripristinato, anche se si sta renderizzando lo stesso componente.
403403
404404
<Sandpack>
405405
@@ -496,13 +496,13 @@ textarea {
496496
497497
<LearnMore path="/learn/preserving-and-resetting-state">
498498
499-
Read **[Preserving and Resetting State](/learn/preserving-and-resetting-state)** to learn the lifetime of state and how to control it.
499+
Leggi **[Preservare e Reimpostare lo State](/learn/preserving-and-resetting-state)** per apprendere la durata dello state e come controllarlo.
500500
501501
</LearnMore>
502502
503-
## Extracting state logic into a reducer {/*extracting-state-logic-into-a-reducer*/}
503+
## Estrarre la logica dello state in un reducer {/*extracting-state-logic-into-a-reducer*/}
504504
505-
Components with many state updates spread across many event handlers can get overwhelming. For these cases, you can consolidate all the state update logic outside your component in a single function, called "reducer". Your event handlers become concise because they only specify the user "actions". At the bottom of the file, the reducer function specifies how the state should update in response to each action!
505+
I componenti con molte aggiornamenti dello state distribuiti su numerosi gestori di eventi possono diventare complessi. Per questi casi, puoi consolidare tutta la logica di aggiornamento dello state al di fuori del tuo componente in una singola funzione, chiamata "riduttore" (reducer). I tuoi gestori di eventi diventano concisi perché specificano solo le "azioni" dell'utente. In fondo al file, la funzione del riduttore specifica come lo state dovrebbe aggiornarsi in risposta a ciascuna azione!
506506

507507
<Sandpack>
508508

@@ -693,15 +693,15 @@ ul, li { margin: 0; padding: 0; }
693693

694694
<LearnMore path="/learn/extracting-state-logic-into-a-reducer">
695695

696-
Read **[Extracting State Logic into a Reducer](/learn/extracting-state-logic-into-a-reducer)** to learn how to consolidate logic in the reducer function.
696+
Leggi **[Estrarre la Logica dello State in un Reducer](/learn/extracting-state-logic-into-a-reducer)** per apprendere come consolidare la logica nel reducer della funzione.
697697

698698
</LearnMore>
699699

700-
## Passing data deeply with context {/*passing-data-deeply-with-context*/}
700+
## Passaggio di dati in profondità con il context {/*passing-data-deeply-with-context*/}
701701

702-
Usually, you will pass information from a parent component to a child component via props. But passing props can become inconvenient if you need to pass some prop through many components, or if many components need the same information. Context lets the parent component make some information available to any component in the tree below it—no matter how deep it is—without passing it explicitly through props.
702+
Di solito, passerai le informazioni da un componente genitore a un componente figlio tramite le props. Tuttavia, il passaggio delle props può diventare scomodo se devi passare una determinata prop attraverso molti componenti o se molti componenti necessitano delle stesse informazioni. Il context consente al componente genitore di rendere disponibili alcune informazioni a tutti i componenti nell'albero sottostante, indipendentemente dalla profondità, senza passarle esplicitamente tramite le props.
703703
704-
Here, the `Heading` component determines its heading level by "asking" the closest `Section` for its level. Each `Section` tracks its own level by asking the parent `Section` and adding one to it. Every `Section` provides information to all components below it without passing props--it does that through context.
704+
In questo esempio, il componente `Heading` determina il livello del titolo "chiedendo" al componente `Section` più vicino il suo livello. Ogni `Section` tiene traccia del proprio livello chiedendo al `Section` genitore e aggiungendo uno. Ogni `Section` fornisce informazioni a tutti i componenti sottostanti senza passare le props in modo esplicito: lo fa attraverso il context.
705705
706706
<Sandpack>
707707
@@ -795,15 +795,15 @@ export const LevelContext = createContext(0);
795795
796796
<LearnMore path="/learn/passing-data-deeply-with-context">
797797
798-
Read **[Passing Data Deeply with Context](/learn/passing-data-deeply-with-context)** to learn about using context as an alternative to passing props.
798+
Leggi **[Passaggio di Dati in Profondità con il Context](/learn/passing-data-deeply-with-context)** per apprendere come utilizzare il context come alternativa al passaggio di props.
799799
800800
</LearnMore>
801801
802-
## Scaling up with reducer and context {/*scaling-up-with-reducer-and-context*/}
802+
## Scalare con reducer e context {/*scaling-up-with-reducer-and-context*/}
803803
804-
Reducers let you consolidate a component’s state update logic. Context lets you pass information deep down to other components. You can combine reducers and context together to manage state of a complex screen.
804+
I reducer ti permettono di consolidare la logica di aggiornamento dello state di un componente. Il contesto ti permette di passare informazioni in profondità ad altri componenti. Puoi combinare i reducer e il context insieme per gestire lo state di una schermata complessa.
805805
806-
With this approach, a parent component with complex state manages it with a reducer. Other components anywhere deep in the tree can read its state via context. They can also dispatch actions to update that state.
806+
Con questo approccio, un componente genitore con uno state complesso lo gestisce con un riduttore. Altri componenti situati in qualsiasi punto dell'albero possono leggere il suo state tramite il contesto. Possono anche inviare azioni per aggiornare tale state.
807807

808808
<Sandpack>
809809

@@ -1006,12 +1006,12 @@ ul, li { margin: 0; padding: 0; }
10061006

10071007
<LearnMore path="/learn/scaling-up-with-reducer-and-context">
10081008

1009-
Read **[Scaling Up with Reducer and Context](/learn/scaling-up-with-reducer-and-context)** to learn how state management scales in a growing app.
1009+
Leggi **[Scalare con Reducer e Context](/learn/scaling-up-with-reducer-and-context)** per apprendere come la gestione dello state si scala in un'applicazione in crescita.
10101010
10111011
</LearnMore>
10121012
1013-
## What's next? {/*whats-next*/}
1013+
## Cosa fare dopo? {/*whats-next*/}
10141014
1015-
Head over to [Reacting to Input with State](/learn/reacting-to-input-with-state) to start reading this chapter page by page!
1015+
Vai su [Reacting to Input with State](/learn/reacting-to-input-with-state) per iniziare a leggere questo capitolo pagina per pagina!
10161016
1017-
Or, if you're already familiar with these topics, why not read about [Escape Hatches](/learn/escape-hatches)?
1017+
Oppure, se sei già familiare con questi argomenti, perché non leggere su [Soluzioni alternative](/learn/escape-hatches)?

src/sidebarHome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"path": "/learn/adding-interactivity"
2828
},
2929
{
30-
"title": "Managing State",
30+
"title": "Gestione dello State",
3131
"path": "/learn/managing-state"
3232
},
3333
{

src/sidebarLearn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
]
126126
},
127127
{
128-
"title": "Managing State",
128+
"title": "Gestione dello State",
129129
"path": "/learn/managing-state",
130130
"tags": ["intermediate"],
131131
"routes": [

0 commit comments

Comments
 (0)