-
Notifications
You must be signed in to change notification settings - Fork 316
docs(pt-br): tradução da referencia useState #782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
@bdsqqq por favor me adicionar como Assignees. Iniciei a revisão. |
não tenho permissão para adicionar, acredito que precise ser um mantenedor |
Ah, tudo bem. Achei que o autor tinha essa permissão. Vou continuar de qualquer forma. Devo entregar até o fds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grande parte das correções está na regra do Glossary sobre não traduzir código. Além disso sugeri algumas alterações de string (permitido no Glossary). Tentei deixar alguns trechos mais compreensivos. Sobre termos, as principais alterações estão relacionadas à re-render e state (discussão: #1075 ).
Uma sugestão global é que como tem muitos exemplos com TODO acho interessante alterar para TASK, pois todo é uma palavra em português e a leitura pode confundir. Não consegui colocar sugestão de código em todas estas partes, pois só tenho permissão de sugestão onde foi alterado.
Qualquer dúvida, fico à disposição. Sendo esta uma página tão importante, espero que seja tão logo aprovada e publicada.
@@ -4,7 +4,7 @@ title: useState | |||
|
|||
<Intro> | |||
|
|||
`useState` is a React Hook that lets you add a [state variable](/learn/state-a-components-memory) to your component. | |||
`useState` é um Hook do React que permite adicionar uma [variável de state](/learn/state-a-components-memory) ao seu componente. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sugiro manter "variável de estado".
mais detalhes em #1075
@@ -4,7 +4,7 @@ title: useState | |||
|
|||
<Intro> | |||
|
|||
`useState` is a React Hook that lets you add a [state variable](/learn/state-a-components-memory) to your component. | |||
`useState` é um Hook do React que permite adicionar uma [variável de state](/learn/state-a-components-memory) ao seu componente. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`useState` é um Hook do React que permite adicionar uma [variável de state](/learn/state-a-components-memory) ao seu componente. | |
`useState` é um Hook do React que permite adicionar uma [variável de estado](/learn/state-a-components-memory) ao seu componente. |
|
||
### `useState(initialState)` {/*usestate*/} | ||
|
||
Call `useState` at the top level of your component to declare a [state variable.](/learn/state-a-components-memory) | ||
Chame `useState` no nível superior do seu componente para declarar uma [variável de state.](/learn/state-a-components-memory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chame `useState` no nível superior do seu componente para declarar uma [variável de state.](/learn/state-a-components-memory) | |
Chame `useState` no nível superior do seu componente para declarar uma [variável de estado.](/learn/state-a-components-memory) |
|
||
* The `set` function **only updates the state variable for the *next* render**. If you read the state variable after calling the `set` function, [you will still get the old value](#ive-updated-the-state-but-logging-gives-me-the-old-value) that was on the screen before your call. | ||
* A função `set` **apenas atualiza a variável de state para a *próxima* renderização**. Se você ler a variável de state após chamar a função `set`, [você ainda obterá o valor antigo](#ive-updated-the-state-but-logging-gives-me-the-old-value) que estava na tela antes da sua chamada. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* A função `set` **apenas atualiza a variável de state para a *próxima* renderização**. Se você ler a variável de state após chamar a função `set`, [você ainda obterá o valor antigo](#ive-updated-the-state-but-logging-gives-me-the-old-value) que estava na tela antes da sua chamada. | |
* A função `set` **apenas atualiza a variável de estado para a *próxima* renderização**. Se você ler a variável de estado após chamar a função `set`, [você ainda obterá o valor antigo](#ive-updated-the-state-but-logging-gives-me-the-old-value) que estava na tela antes da sua chamada. |
|
||
1. The <CodeStep step={1}>current state</CodeStep> of this state variable, initially set to the <CodeStep step={3}>initial state</CodeStep> you provided. | ||
2. The <CodeStep step={2}>`set` function</CodeStep> that lets you change it to any other value in response to interaction. | ||
1. O <CodeStep step={1}>state atual</CodeStep> desta variável de state, inicialmente definido como o <CodeStep step={3}>state inicial</CodeStep> que você forneceu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. O <CodeStep step={1}>state atual</CodeStep> desta variável de state, inicialmente definido como o <CodeStep step={3}>state inicial</CodeStep> que você forneceu. | |
1. O <CodeStep step={1}>state atual</CodeStep> desta variável de estado, inicialmente definido como o <CodeStep step={3}>state inicial</CodeStep> que você forneceu. |
``` | ||
|
||
You mutated an existing `obj` object and passed it back to `setObj`, so React ignored the update. To fix this, you need to ensure that you're always [_replacing_ objects and arrays in state instead of _mutating_ them](#updating-objects-and-arrays-in-state): | ||
Você mutou um objeto `obj` existente e o passou de volta para `setObj`, então o React ignorou a atualização. Para corrigir isso, você precisa garantir que sempre está _substituindo_ objetos e arrays no state em vez de _mutá-los_: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Você mutou um objeto `obj` existente e o passou de volta para `setObj`, então o React ignorou a atualização. Para corrigir isso, você precisa garantir que sempre está _substituindo_ objetos e arrays no state em vez de _mutá-los_: | |
Você alterou um objeto `obj` existente e o passou de volta para `setObj`, então o React ignorou a atualização. Para corrigir isso, você precisa garantir que sempre está _substituindo_ objetos e arrays no state em vez de _realizar uma mutação_: |
|
||
For example, this impure updater function mutates an array in state: | ||
Por exemplo, esta função atualizadora impura muta um array no state: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por exemplo, esta função atualizadora impura muta um array no state: | |
Por exemplo, esta função atualizadora impura realiza mutação em um array no state: |
|
||
```js {2,3} | ||
setTodos(prevTodos => { | ||
// 🚩 Mistake: mutating state | ||
// 🚩 Erro: mutando o state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 🚩 Erro: mutando o state | |
// 🚩 Erro: realiza mutação no state |
|
||
--- | ||
|
||
### I'm trying to set state to a function, but it gets called instead {/*im-trying-to-set-state-to-a-function-but-it-gets-called-instead*/} | ||
### Estou tentando definir o state para uma função, mas ela é chamada em vez disso {/*im-trying-to-set-state-to-a-function-but-it-gets-called-instead*/} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Estou tentando definir o state para uma função, mas ela é chamada em vez disso {/*im-trying-to-set-state-to-a-function-but-it-gets-called-instead*/} | |
### Estou tentando definir o state para uma função, mas em vez disso ela é executada {/*im-trying-to-set-state-to-a-function-but-it-gets-called-instead*/} |
@@ -1279,7 +1279,7 @@ function handleClick() { | |||
} | |||
``` | |||
|
|||
Because you're passing a function, React assumes that `someFunction` is an [initializer function](#avoiding-recreating-the-initial-state), and that `someOtherFunction` is an [updater function](#updating-state-based-on-the-previous-state), so it tries to call them and store the result. To actually *store* a function, you have to put `() =>` before them in both cases. Then React will store the functions you pass. | |||
Porque você está passando uma função, o React assume que `someFunction` é uma [função inicializadora](#avoiding-recreating-the-initial-state), e que `someOtherFunction` é uma [função atualizadora](#updating-state-based-on-the-previous-state), então tenta chamá-las e armazenar o resultado. Para realmente *armazenar* uma função, você precisa colocar `() =>` antes delas em ambos os casos. Então o React armazenará as funções que você passa. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Porque você está passando uma função, o React assume que `someFunction` é uma [função inicializadora](#avoiding-recreating-the-initial-state), e que `someOtherFunction` é uma [função atualizadora](#updating-state-based-on-the-previous-state), então tenta chamá-las e armazenar o resultado. Para realmente *armazenar* uma função, você precisa colocar `() =>` antes delas em ambos os casos. Então o React armazenará as funções que você passa. | |
Porque você está passando uma função, o React assume que `someFunction` é uma [função inicializadora](#avoiding-recreating-the-initial-state), e que `someOtherFunction` é uma [função atualizadora](#updating-state-based-on-the-previous-state), então tenta chamá-las e armazena o resultado. Para realmente *armazenar* uma função, você precisa colocar `() =>` antes delas em ambos os casos. Então o React irá armazenar as funções que você passa. |
@bdsqqq finalizei a revisão. Qualquer dúvida sobre as alterações podemos discutir aqui. |
see: #555, #689