Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bdsqqq
Copy link

@bdsqqq bdsqqq commented Sep 12, 2024

see: #555, #689

Copy link

vercel bot commented Sep 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
pt-br-legacy-reactjs-org ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 0:51am

@lanamesquita
Copy link
Contributor

@bdsqqq por favor me adicionar como Assignees. Iniciei a revisão.

@bdsqqq
Copy link
Author

bdsqqq commented Mar 25, 2025

@bdsqqq por favor me adicionar como Assignees. Iniciei a revisão.

não tenho permissão para adicionar, acredito que precise ser um mantenedor

@lanamesquita
Copy link
Contributor

@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.

Copy link
Contributor

@lanamesquita lanamesquita left a 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.
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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_:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 🚩 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*/}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@lanamesquita
Copy link
Contributor

@bdsqqq finalizei a revisão. Qualquer dúvida sobre as alterações podemos discutir aqui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review A pull request ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants