Skip to content

Commit 4a71eb4

Browse files
Translate react-calls-components-and-hooks.md to pt-br (#932)
1 parent 20a5857 commit 4a71eb4

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,100 @@
11
---
2-
title: React calls Components and Hooks
2+
title: O React chama Componentes e Hooks
33
---
44

55
<Intro>
6-
React is responsible for rendering components and Hooks when necessary to optimize the user experience. It is declarative: you tell React what to render in your component’s logic, and React will figure out how best to display it to your user.
6+
O React é responsável por renderizar componentes e Hooks quando necessário para otimizar a experiência do usuário. É declarativo: você diz ao React o que renderizar na lógica do seu componente, e o React descobrirá a melhor forma de exibi-lo para o seu usuário.
77
</Intro>
88

99
<InlineToc />
1010

1111
---
1212

13-
## Never call component functions directly {/*never-call-component-functions-directly*/}
14-
Components should only be used in JSX. Don't call them as regular functions. React should call it.
13+
## Nunca chame funções de componentes diretamente {/*never-call-component-functions-directly*/}
14+
Os componentes devem ser usados apenas em JSX. Não os chame como funções regulares. O React deve chamá-los.
1515

16-
React must decide when your component function is called [during rendering](/reference/rules/components-and-hooks-must-be-pure#how-does-react-run-your-code). In React, you do this using JSX.
16+
O React deve decidir quando a função do seu componente é chamada [durante a renderização](/reference/rules/components-and-hooks-must-be-pure#how-does-react-run-your-code). No React, você faz isso usando JSX.
1717

1818
```js {2}
1919
function BlogPost() {
20-
return <Layout><Article /></Layout>; //Good: Only use components in JSX
20+
return <Layout><Article /></Layout>; //Bom: Use apenas componentes em JSX
2121
}
2222
```
2323

2424
```js {2}
2525
function BlogPost() {
26-
return <Layout>{Article()}</Layout>; // 🔴 Bad: Never call them directly
26+
return <Layout>{Article()}</Layout>; // 🔴 Ruim: Nunca os chame diretamente
2727
}
2828
```
2929

30-
If a component contains Hooks, it's easy to violate the [Rules of Hooks](/reference/rules/rules-of-hooks) when components are called directly in a loop or conditionally.
30+
Se um componente contém Hooks, é fácil violar as [Regras dos Hooks](/reference/rules/rules-of-hooks) quando os componentes são chamados diretamente em um loop ou condicionalmente.
3131

32-
Letting React orchestrate rendering also allows a number of benefits:
32+
Deixar o React orquestrar a renderização também oferece uma série de benefícios:
3333

34-
* **Components become more than functions.** React can augment them with features like _local state_ through Hooks that are tied to the component's identity in the tree.
35-
* **Component types participate in reconciliation.** By letting React call your components, you also tell it more about the conceptual structure of your tree. For example, when you move from rendering `<Feed>` to the `<Profile>` page, React won’t attempt to re-use them.
36-
* **React can enhance your user experience.** For example, it can let the browser do some work between component calls so that re-rendering a large component tree doesn’t block the main thread.
37-
* **A better debugging story.** If components are first-class citizens that the library is aware of, we can build rich developer tools for introspection in development.
38-
* **More efficient reconciliation.** React can decide exactly which components in the tree need re-rendering and skip over the ones that don't. That makes your app faster and more snappy.
34+
* **Os componentes se tornam mais do que funções.** O React pode aumentá-los com recursos como _estado local_ através de Hooks que estão ligados à identidade do componente na árvore.
35+
* **Os tipos de componentes participam da reconciliação.** Ao deixar o React chamar seus componentes, você também diz mais sobre a estrutura conceitual de sua árvore. Por exemplo, quando você muda de renderizar `<Feed>` para a página `<Profile>`, o React não tentará reutilizá-los.
36+
* **O React pode melhorar a experiência do usuário.** Por exemplo, ele pode permitir que o navegador realize algumas tarefas entre chamadas de componentes para que a re-renderização de uma grande árvore de componentes não bloqueie a thread principal.
37+
* **Uma melhor história de depuração.** Se os componentes são cidadãos de primeira classe dos quais a biblioteca está ciente, podemos construir ferramentas ricas para introspecção em desenvolvimento.
38+
* **Reconciliação mais eficiente.** O React pode decidir exatamente quais componentes na árvore precisam ser re-renderizados e pular aqueles que não precisam. Isso torna seu aplicativo mais rápido e mais ágil.
3939

4040
---
4141

42-
## Never pass around Hooks as regular values {/*never-pass-around-hooks-as-regular-values*/}
42+
## Nunca passe Hooks como valores regulares {/*never-pass-around-hooks-as-regular-values*/}
4343

44-
Hooks should only be called inside of components or Hooks. Never pass it around as a regular value.
44+
Os Hooks devem ser chamados apenas dentro de componentes ou Hooks. Nunca os passe como um valor regular.
4545

46-
Hooks allow you to augment a component with React features. They should always be called as a function, and never passed around as a regular value. This enables _local reasoning_, or the ability for developers to understand everything a component can do by looking at that component in isolation.
46+
Os Hooks permitem que você aumente um componente com recursos do React. Eles devem sempre ser chamados como uma função, e nunca passados como um valor regular. Isso possibilita um _raciocínio local_, ou a capacidade dos desenvolvedores de entender tudo que um componente pode fazer ao olhar para aquele componente isoladamente.
4747

48-
Breaking this rule will cause React to not automatically optimize your component.
48+
Quebrar essa regra fará com que o React não otimize automaticamente seu componente.
4949

50-
### Don't dynamically mutate a Hook {/*dont-dynamically-mutate-a-hook*/}
50+
### Não mude um Hook dinamicamente {/*dont-dynamically-mutate-a-hook*/}
5151

52-
Hooks should be as "static" as possible. This means you shouldn't dynamically mutate them. For example, this means you shouldn't write higher order Hooks:
52+
Os Hooks devem ser o mais "estáticos" possível. Isso significa que você não deve mudá-los dinamicamente. Por exemplo, isso significa que você não deve escrever Hooks de alta ordem:
5353

5454
```js {2}
5555
function ChatInput() {
56-
const useDataWithLogging = withLogging(useData); // 🔴 Bad: don't write higher order Hooks
56+
const useDataWithLogging = withLogging(useData); // 🔴 Ruim: não escreva Hooks de alta ordem
5757
const data = useDataWithLogging();
5858
}
5959
```
6060

61-
Hooks should be immutable and not be mutated. Instead of mutating a Hook dynamically, create a static version of the Hook with the desired functionality.
61+
Os Hooks devem ser imutáveis e não devem ser mutados. Em vez de mutar um Hook dinamicamente, crie uma versão estática do Hook com a funcionalidade desejada.
6262

6363
```js {2,6}
6464
function ChatInput() {
65-
const data = useDataWithLogging(); //Good: Create a new version of the Hook
65+
const data = useDataWithLogging(); //Bom: Crie uma nova versão do Hook
6666
}
6767

6868
function useDataWithLogging() {
69-
// ... Create a new version of the Hook and inline the logic here
69+
// ... Crie uma nova versão do Hook e inicie a lógica aqui
7070
}
7171
```
7272

73-
### Don't dynamically use Hooks {/*dont-dynamically-use-hooks*/}
73+
### Não use Hooks dinamicamente {/*dont-dynamically-use-hooks*/}
7474

75-
Hooks should also not be dynamically used: for example, instead of doing dependency injection in a component by passing a Hook as a value:
75+
Os Hooks também não devem ser usados dinamicamente: por exemplo, em vez de fazer injeção de dependência em um componente passando um Hook como valor:
7676

7777
```js {2}
7878
function ChatInput() {
79-
return <Button useData={useDataWithLogging} /> // 🔴 Bad: don't pass Hooks as props
79+
return <Button useData={useDataWithLogging} /> // 🔴 Ruim: não passe Hooks como props
8080
}
8181
```
8282

83-
You should always inline the call of the Hook into that component and handle any logic in there.
83+
Você deve sempre iniciar a chamada do Hook dentro desse componente e lidar com qualquer lógica lá.
8484

8585
```js {6}
8686
function ChatInput() {
8787
return <Button />
8888
}
8989

9090
function Button() {
91-
const data = useDataWithLogging(); //Good: Use the Hook directly
91+
const data = useDataWithLogging(); //Bom: Use o Hook diretamente
9292
}
9393

9494
function useDataWithLogging() {
95-
// If there's any conditional logic to change the Hook's behavior, it should be inlined into
96-
// the Hook
95+
// Se houver alguma lógica condicional para mudar o comportamento do Hook, ela deve ser iniciada
96+
// dentro do Hook
9797
}
9898
```
9999

100-
This way, `<Button />` is much easier to understand and debug. When Hooks are used in dynamic ways, it increases the complexity of your app greatly and inhibits local reasoning, making your team less productive in the long term. It also makes it easier to accidentally break the [Rules of Hooks](/reference/rules/rules-of-hooks) that Hooks should not be called conditionally. If you find yourself needing to mock components for tests, it's better to mock the server instead to respond with canned data. If possible, it's also usually more effective to test your app with end-to-end tests.
101-
100+
Dessa forma, `<Button />` é muito mais fácil de entender e depurar. Quando os Hooks são usados de maneiras dinâmicas, isso aumenta muito a complexidade do seu aplicativo e inibe o raciocínio local, tornando sua equipe menos produtiva a longo prazo. Também facilita acidentalmente violar as [Regras dos Hooks](/reference/rules/rules-of-hooks) que afirmam que Hooks não devem ser chamados condicionalmente. Se você se encontrar precisando simular componentes para testes, é melhor simular o servidor em vez de responder com dados fixos. Se possível, também geralmente é mais eficaz testar seu aplicativo com testes de ponta a ponta.

0 commit comments

Comments
 (0)