Skip to content

Commit 7f4e0fb

Browse files
docs: translate scaling-up-with-reducer-and-context.md to Português (Brasil)
1 parent 1d57663 commit 7f4e0fb

1 file changed

Lines changed: 56 additions & 56 deletions

File tree

src/content/learn/scaling-up-with-reducer-and-context.md

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ title: Scaling Up with Reducer and Context
44

55
<Intro>
66

7-
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.
7+
Reducers permitem consolidar a lógica de atualização de estado de um componente. Contexto permite passar informações profundamente para outros componentes. Você pode combinar reducers e contexto juntos para gerenciar o estado de uma tela complexa.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
* How to combine a reducer with context
14-
* How to avoid passing state and dispatch through props
15-
* How to keep context and state logic in a separate file
13+
* Como combinar um reducer com contexto
14+
* Como evitar passar estado e dispatch via props
15+
* Como manter a lógica de contexto e estado em um arquivo separado
1616

1717
</YouWillLearn>
1818

19-
## Combining a reducer with context {/*combining-a-reducer-with-context*/}
19+
## Combinando um reducer com contexto {/*combining-a-reducer-with-context*/}
2020

21-
In this example from [the introduction to reducers](/learn/extracting-state-logic-into-a-reducer), the state is managed by a reducer. The reducer function contains all of the state update logic and is declared at the bottom of this file:
21+
Neste exemplo da [introdução aos reducers](/learn/extracting-state-logic-into-a-reducer), o estado é gerenciado por um reducer. A função reducer contém toda a lógica de atualização de estado e é declarada no final deste arquivo:
2222

2323
<Sandpack>
2424

@@ -207,9 +207,9 @@ ul, li { margin: 0; padding: 0; }
207207

208208
</Sandpack>
209209

210-
A reducer helps keep the event handlers short and concise. However, as your app grows, you might run into another difficulty. **Currently, the `tasks` state and the `dispatch` function are only available in the top-level `TaskApp` component.** To let other components read the list of tasks or change it, you have to explicitly [pass down](/learn/passing-props-to-a-component) the current state and the event handlers that change it as props.
210+
Um reducer ajuda a manter os manipuladores de eventos curtos e concisos. No entanto, à medida que seu aplicativo cresce, você pode encontrar outra dificuldade. **Atualmente, o estado `tasks` e a função `dispatch` estão disponíveis apenas no componente de nível superior `TaskApp`.** Para permitir que outros componentes leiam a lista de tarefas ou a modifiquem, você precisa explicitamente [passar](/learn/passing-props-to-a-component) o estado atual e os manipuladores de eventos que o modificam como props.
211211

212-
For example, `TaskApp` passes a list of tasks and the event handlers to `TaskList`:
212+
Por exemplo, `TaskApp` passa uma lista de tarefas e os manipuladores de eventos para `TaskList`:
213213

214214
```js
215215
<TaskList
@@ -219,7 +219,7 @@ For example, `TaskApp` passes a list of tasks and the event handlers to `TaskLis
219219
/>
220220
```
221221

222-
And `TaskList` passes the event handlers to `Task`:
222+
E `TaskList` passa os manipuladores de eventos para `Task`:
223223

224224
```js
225225
<Task
@@ -229,30 +229,30 @@ And `TaskList` passes the event handlers to `Task`:
229229
/>
230230
```
231231

232-
In a small example like this, this works well, but if you have tens or hundreds of components in the middle, passing down all state and functions can be quite frustrating!
232+
Em um exemplo pequeno como este, isso funciona bem, mas se você tiver dezenas ou centenas de componentes no meio, passar todas as informações de estado e funções pode ser bastante frustrante!
233233

234-
This is why, as an alternative to passing them through props, you might want to put both the `tasks` state and the `dispatch` function [into context.](/learn/passing-data-deeply-with-context) **This way, any component below `TaskApp` in the tree can read the tasks and dispatch actions without the repetitive "prop drilling".**
234+
É por isso que, como alternativa a passá-las via props, você pode querer colocar tanto o estado `tasks` quanto a função `dispatch` [em contexto.](/learn/passing-data-deeply-with-context) **Dessa forma, qualquer componente abaixo de `TaskApp` na árvore pode ler as tarefas e despachar ações sem a repetição de "prop drilling".**
235235

236-
Here is how you can combine a reducer with context:
236+
Veja como você pode combinar um reducer com contexto:
237237

238-
1. **Create** the context.
239-
2. **Put** state and dispatch into context.
240-
3. **Use** context anywhere in the tree.
238+
1. **Crie** o contexto.
239+
2. **Coloque** o estado e o dispatch no contexto.
240+
3. **Use** o contexto em qualquer lugar da árvore.
241241

242-
### Step 1: Create the context {/*step-1-create-the-context*/}
242+
### Passo 1: Crie o contexto {/*step-1-create-the-context*/}
243243

244-
The `useReducer` Hook returns the current `tasks` and the `dispatch` function that lets you update them:
244+
O Hook `useReducer` retorna o `tasks` atual e a função `dispatch` que permite atualizá-los:
245245

246246
```js
247247
const [tasks, dispatch] = useReducer(tasksReducer, initialTasks);
248248
```
249249

250-
To pass them down the tree, you will [create](/learn/passing-data-deeply-with-context#step-2-use-the-context) two separate contexts:
250+
Para passá-los pela árvore, você [criará](/learn/passing-data-deeply-with-context#step-2-use-the-context) dois contextos separados:
251251

252-
- `TasksContext` provides the current list of tasks.
253-
- `TasksDispatchContext` provides the function that lets components dispatch actions.
252+
- `TasksContext` fornece a lista atual de tarefas.
253+
- `TasksDispatchContext` fornece a função que permite aos componentes despachar ações.
254254

255-
Export them from a separate file so that you can later import them from other files:
255+
Exporte-os de um arquivo separado para que você possa importá-los posteriormente de outros arquivos:
256256

257257
<Sandpack>
258258

@@ -448,11 +448,11 @@ ul, li { margin: 0; padding: 0; }
448448

449449
</Sandpack>
450450

451-
Here, you're passing `null` as the default value to both contexts. The actual values will be provided by the `TaskApp` component.
451+
Aqui, você está passando `null` como valor padrão para ambos os contextos. Os valores reais serão fornecidos pelo componente `TaskApp`.
452452

453-
### Step 2: Put state and dispatch into context {/*step-2-put-state-and-dispatch-into-context*/}
453+
### Passo 2: Coloque o estado e o dispatch no contexto {/*step-2-put-state-and-dispatch-into-context*/}
454454

455-
Now you can import both contexts in your `TaskApp` component. Take the `tasks` and `dispatch` returned by `useReducer()` and [provide them](/learn/passing-data-deeply-with-context#step-3-provide-the-context) to the entire tree below:
455+
Agora você pode importar ambos os contextos em seu componente `TaskApp`. Pegue os `tasks` e `dispatch` retornados por `useReducer()` e [forneça-os](/learn/passing-data-deeply-with-context#step-3-provide-the-context) para toda a árvore abaixo:
456456

457457
```js {4,7-8}
458458
import { TasksContext, TasksDispatchContext } from './TasksContext.js';
@@ -470,7 +470,7 @@ export default function TaskApp() {
470470
}
471471
```
472472

473-
For now, you pass the information both via props and in context:
473+
Por enquanto, você passa as informações tanto via props quanto em contexto:
474474

475475
<Sandpack>
476476

@@ -669,11 +669,11 @@ ul, li { margin: 0; padding: 0; }
669669

670670
</Sandpack>
671671

672-
In the next step, you will remove prop passing.
672+
Na próxima etapa, você removerá a passagem de props.
673673

674-
### Step 3: Use context anywhere in the tree {/*step-3-use-context-anywhere-in-the-tree*/}
674+
### Passo 3: Use o contexto em qualquer lugar da árvore {/*step-3-use-context-anywhere-in-the-tree*/}
675675

676-
Now you don't need to pass the list of tasks or the event handlers down the tree:
676+
Agora você não precisa passar a lista de tarefas ou os manipuladores de eventos pela árvore:
677677

678678
```js {4-5}
679679
<TasksContext value={tasks}>
@@ -685,15 +685,15 @@ Now you don't need to pass the list of tasks or the event handlers down the tree
685685
</TasksContext>
686686
```
687687

688-
Instead, any component that needs the task list can read it from the `TasksContext`:
688+
Em vez disso, qualquer componente que precise da lista de tarefas pode lê-la do `TasksContext`:
689689

690690
```js {2}
691691
export default function TaskList() {
692692
const tasks = useContext(TasksContext);
693693
// ...
694694
```
695695
696-
To update the task list, any component can read the `dispatch` function from context and call it:
696+
Para atualizar a lista de tarefas, qualquer componente pode ler a função `dispatch` do contexto e chamá-la:
697697
698698
```js {3,9-13}
699699
export default function AddTask() {
@@ -713,7 +713,7 @@ export default function AddTask() {
713713
// ...
714714
```
715715
716-
**The `TaskApp` component does not pass any event handlers down, and the `TaskList` does not pass any event handlers to the `Task` component either.** Each component reads the context that it needs:
716+
**O componente `TaskApp` não passa nenhum manipulador de eventos para baixo, e o `TaskList` também não passa nenhum manipulador de eventos para o componente `Task`.** Cada componente lê o contexto que precisa:
717717
718718
<Sandpack>
719719
@@ -897,11 +897,11 @@ ul, li { margin: 0; padding: 0; }
897897
898898
</Sandpack>
899899
900-
**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.
900+
**O estado ainda "vive" no componente de nível superior `TaskApp`, gerenciado com `useReducer`.** Mas seus `tasks` e `dispatch` agora estão disponíveis para todos os componentes abaixo na árvore, importando e usando esses contextos.
901901
902-
## Moving all wiring into a single file {/*moving-all-wiring-into-a-single-file*/}
902+
## Mover toda a lógica para um único arquivo {/*moving-all-wiring-into-a-single-file*/}
903903
904-
You don't have to do this, but you could further declutter the components by moving both reducer and context into a single file. Currently, `TasksContext.js` contains only two context declarations:
904+
Você não precisa fazer isso, mas pode simplificar ainda mais os componentes movendo o reducer e o context para um único arquivo. Atualmente, `TasksContext.js` contém apenas duas declarações de context:
905905
906906
```js
907907
import { createContext } from 'react';
@@ -910,11 +910,11 @@ export const TasksContext = createContext(null);
910910
export const TasksDispatchContext = createContext(null);
911911
```
912912
913-
This file is about to get crowded! You'll move the reducer into that same file. Then you'll declare a new `TasksProvider` component in the same file. This component will tie all the pieces together:
913+
Este arquivo está prestes a ficar lotado! Você moverá o reducer para esse mesmo arquivo. Em seguida, declarará um novo componente `TasksProvider` no mesmo arquivo. Este componente unirá todas as peças:
914914
915-
1. It will manage the state with a reducer.
916-
2. It will provide both contexts to components below.
917-
3. It will [take `children` as a prop](/learn/passing-props-to-a-component#passing-jsx-as-children) so you can pass JSX to it.
915+
1. Ele gerenciará o estado com um reducer.
916+
2. Ele fornecerá ambos os contexts para os componentes abaixo.
917+
3. Ele [receberá `children` como prop](/learn/passing-props-to-a-component#passing-jsx-as-children) para que você possa passar JSX para ele.
918918
919919
```js
920920
export function TasksProvider({ children }) {
@@ -930,7 +930,7 @@ export function TasksProvider({ children }) {
930930
}
931931
```
932932
933-
**This removes all the complexity and wiring from your `TaskApp` component:**
933+
**Isso remove toda a complexidade e a lógica de conexão do seu componente `TaskApp`:**
934934
935935
<Sandpack>
936936
@@ -1121,7 +1121,7 @@ ul, li { margin: 0; padding: 0; }
11211121
11221122
</Sandpack>
11231123
1124-
You can also export functions that _use_ the context from `TasksContext.js`:
1124+
Você também pode exportar funções que _usam_ o context de `TasksContext.js`:
11251125
11261126
```js
11271127
export function useTasks() {
@@ -1133,14 +1133,14 @@ export function useTasksDispatch() {
11331133
}
11341134
```
11351135
1136-
When a component needs to read context, it can do it through these functions:
1136+
Quando um componente precisar ler o context, ele poderá fazer isso através dessas funções:
11371137
11381138
```js
11391139
const tasks = useTasks();
11401140
const dispatch = useTasksDispatch();
11411141
```
11421142
1143-
This doesn't change the behavior in any way, but it lets you later split these contexts further or add some logic to these functions. **Now all of the context and reducer wiring is in `TasksContext.js`. This keeps the components clean and uncluttered, focused on what they display rather than where they get the data:**
1143+
Isso não altera o comportamento de forma alguma, mas permite que você divida esses contexts posteriormente ou adicione alguma lógica a essas funções. **Agora, toda a lógica de context e reducer está em `TasksContext.js`. Isso mantém os componentes limpos e organizados, focados no que eles exibem em vez de onde obtêm os dados:**
11441144
11451145
<Sandpack>
11461146
@@ -1340,26 +1340,26 @@ ul, li { margin: 0; padding: 0; }
13401340
13411341
</Sandpack>
13421342
1343-
You can think of `TasksProvider` as a part of the screen that knows how to deal with tasks, `useTasks` as a way to read them, and `useTasksDispatch` as a way to update them from any component below in the tree.
1343+
Você pode pensar em `TasksProvider` como uma parte da tela que sabe como lidar com tarefas, `useTasks` como uma forma de lê-las e `useTasksDispatch` como uma forma de atualizá-las a partir de qualquer componente abaixo na árvore.
13441344
13451345
<Note>
13461346
1347-
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.
1347+
Funções como `useTasks` e `useTasksDispatch` são chamadas de *[Custom Hooks.](/learn/reusing-logic-with-custom-hooks)* Sua função é considerada um custom Hook se o nome dela começar com `use`. Isso permite que você use outros Hooks, como `useContext`, dentro dela.
13481348
13491349
</Note>
13501350
1351-
As your app grows, you may have many context-reducer pairs like this. This is a powerful way to scale your app and [lift state up](/learn/sharing-state-between-components) without too much work whenever you want to access the data deep in the tree.
1351+
À medida que seu aplicativo cresce, você pode ter muitos pares de context-reducer como este. Esta é uma maneira poderosa de escalar seu aplicativo e [elevar o estado](/learn/sharing-state-between-components) sem muito trabalho sempre que quiser acessar os dados profundamente na árvore.
13521352
13531353
<Recap>
13541354
1355-
- You can combine reducer with context to let any component read and update state above it.
1356-
- To provide state and the dispatch function to components below:
1357-
1. Create two contexts (for state and for dispatch functions).
1358-
2. Provide both contexts from the component that uses the reducer.
1359-
3. Use either context from components that need to read them.
1360-
- You can further declutter the components by moving all wiring into one file.
1361-
- You can export a component like `TasksProvider` that provides context.
1362-
- You can also export custom Hooks like `useTasks` and `useTasksDispatch` to read it.
1363-
- You can have many context-reducer pairs like this in your app.
1364-
1365-
</Recap>
1355+
- Você pode combinar reducer com context para permitir que qualquer componente leia e atualize o estado acima dele.
1356+
- Para fornecer o estado e a função de dispatch aos componentes abaixo:
1357+
1. Crie dois contexts (para o estado e para as funções de dispatch).
1358+
2. Forneça ambos os contexts do componente que usa o reducer.
1359+
3. Use qualquer um dos contexts dos componentes que precisam lê-los.
1360+
- Você pode simplificar ainda mais os componentes movendo toda a lógica para um único arquivo.
1361+
- Você pode exportar um componente como `TasksProvider` que fornece o context.
1362+
- Você também pode exportar custom Hooks como `useTasks` e `useTasksDispatch` para lê-lo.
1363+
- Você pode ter muitos pares de context-reducer como este em seu aplicativo.
1364+
1365+
</Recap>

0 commit comments

Comments
 (0)