Scaling Up With Reducer and Context by Fabs97 · Pull Request #525 · reactjs/it.react.dev
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perdona il ritardo! 🙈
Qualche piccola correzione
| </Sandpack> | ||
|
|
||
| **The state still "lives" in the top-level `TaskApp` component, managed with `useReducer`.** But its `tasks` and `dispatch` are now available to every component below in the tree by importing and using these contexts. | ||
| **Lo stato ancora "vive" nel componente di primo livello `TaskApp`, gestito con `useReducer`.** Ma i suoi `tasks` e `dispatch` sono ora disponibili ad ogni componente nell'albero sottostante semplicemente importando e usando questi context. |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosa ne pensi?
| **Lo stato ancora "vive" nel componente di primo livello `TaskApp`, gestito con `useReducer`.** Ma i suoi `tasks` e `dispatch` sono ora disponibili ad ogni componente nell'albero sottostante semplicemente importando e usando questi context. | |
| **Lo stato continua a "vivere" nel componente di primo livello `TaskApp`, gestito con `useReducer`.** Ma i suoi `tasks` e `dispatch` sono ora disponibili ad ogni componente nell'albero sottostante semplicemente importando e usando questi context. |
Comment on lines +176 to +178
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "tags": [ | |
| "advanced" | |
| ], | |
| "tags": ["advanced"], |
Comment on lines +139 to +141
| "tags": [ | ||
| "intermediate" | ||
| ], |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "tags": [ | |
| "intermediate" | |
| ], | |
| "tags": ["intermediate"], |
| - Puoi esportare un componente come `TasksProvider` che fornisce il context. | ||
| - Puoi anche esportare dei Ganci personalizzati come `useTasks` e `useTasksDispatch` per leggerlo. | ||
| - Puoi avere molte coppie context-reducer come questa nella tua app. | ||
| - |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ### Passo 1: Crea il context {/*step-1-create-the-context*/} | ||
|
|
||
| The `useReducer` Hook returns the current `tasks` and the `dispatch` function that lets you update them: | ||
| Il gancio `useReducer` ritorna le `tasks` attuali e la funzione `dispatch` che ti permette di aggiornarle: |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Il gancio `useReducer` ritorna le `tasks` attuali e la funzione `dispatch` che ti permette di aggiornarle: | |
| L'hook `useReducer` ritorna le `tasks` attuali e la funzione `dispatch` che ti permette di aggiornarle: |
| <Note> | ||
|
|
||
| Functions like `useTasks` and `useTasksDispatch` are called *[Custom Hooks.](/learn/reusing-logic-with-custom-hooks)* Your function is considered a custom Hook if its name starts with `use`. This lets you use other Hooks, like `useContext`, inside it. | ||
| Funzioni come `useTasks` e `useTasksDispatch` sono chiamate *[Ganci Personalizzati.](/learn/reusing-logic-with-custom-hooks)* La tua funzione è considerata un Gancio personalizzato se il nome comincia con `use`. Questo ti permette di usare altri Ganci, tipo `useContext`, dentro di esso. |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Funzioni come `useTasks` e `useTasksDispatch` sono chiamate *[Ganci Personalizzati.](/learn/reusing-logic-with-custom-hooks)* La tua funzione è considerata un Gancio personalizzato se il nome comincia con `use`. Questo ti permette di usare altri Ganci, tipo `useContext`, dentro di esso. | |
| Funzioni come `useTasks` e `useTasksDispatch` sono chiamate *[Hooks Personalizzati.](/learn/reusing-logic-with-custom-hooks)* La tua funzione è considerata un Hook personalizzato se il nome comincia con `use`. Questo ti permette di usare altri Hooks, tipo `useContext`, dentro di esso. |
| 3. Usa uno dei due context dai componente che ne hanno bisogno per leggerli. | ||
| - Puoi ulteriormente ordinare i componenti muovendo tutte le connessioni in un unico file. | ||
| - Puoi esportare un componente come `TasksProvider` che fornisce il context. | ||
| - Puoi anche esportare dei Ganci personalizzati come `useTasks` e `useTasksDispatch` per leggerlo. |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Puoi anche esportare dei Ganci personalizzati come `useTasks` e `useTasksDispatch` per leggerlo. | |
| - Puoi anche esportare degli Hooks personalizzati come `useTasks` e `useTasksDispatch` per leggerlo. |