Skip to content

Commit 2a44161

Browse files
Translate useOptimistic.md to Portuguese (#1060)
1 parent 581e3c6 commit 2a44161

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/content/reference/react/useOptimistic.md

+16-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useOptimistic
44

55
<Intro>
66

7-
`useOptimistic` is a React Hook that lets you optimistically update the UI.
7+
`useOptimistic` é um Hook do React que permite que você atualize a UI de forma otimista.
88

99
```js
1010
const [optimisticState, addOptimistic] = useOptimistic(state, updateFn);
@@ -16,13 +16,13 @@ title: useOptimistic
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## Referência {/*reference*/}
2020

2121
### `useOptimistic(state, updateFn)` {/*use*/}
2222

23-
`useOptimistic` is a React Hook that lets you show a different state while an async action is underway. It accepts some state as an argument and returns a copy of that state that can be different during the duration of an async action such as a network request. You provide a function that takes the current state and the input to the action, and returns the optimistic state to be used while the action is pending.
23+
`useOptimistic` é um Hook do React que permite que você mostre um estado diferente enquanto uma ação assíncrona está em andamento. Ele aceita algum estado como argumento e retorna uma cópia desse estado que pode ser diferente durante a duração de uma ação assíncrona, como uma requisição de rede. Você fornece uma função que recebe o estado atual e a entrada para a ação, e retorna o estado otimista a ser usado enquanto a ação está pendente.
2424

25-
This state is called the "optimistic" state because it is usually used to immediately present the user with the result of performing an action, even though the action actually takes time to complete.
25+
Este estado é chamado de estado "otimista" porque geralmente é usado para apresentar imediatamente ao usuário o resultado da execução de uma ação, mesmo que a ação realmente leve tempo para ser concluída.
2626

2727
```js
2828
import { useOptimistic } from 'react';
@@ -39,32 +39,30 @@ function AppContainer() {
3939
}
4040
```
4141

42-
[See more examples below.](#usage)
42+
[Veja mais exemplos abaixo.](#usage)
4343

44-
#### Parameters {/*parameters*/}
44+
#### Parâmetros {/*parameters*/}
4545

46-
* `state`: the value to be returned initially and whenever no action is pending.
47-
* `updateFn(currentState, optimisticValue)`: a function that takes the current state and the optimistic value passed to `addOptimistic` and returns the resulting optimistic state. It must be a pure function. `updateFn` takes in two parameters. The `currentState` and the `optimisticValue`. The return value will be the merged value of the `currentState` and `optimisticValue`.
46+
* `state`: o valor a ser retornado inicialmente e sempre que nenhuma ação estiver pendente.
47+
* `updateFn(currentState, optimisticValue)`: uma função que recebe o estado atual e o valor otimista passado para `addOptimistic` e retorna o estado otimista resultante. Deve ser uma função pura. `updateFn` recebe dois parâmetros, o `currentState` e o `optimisticValue`. O valor de retorno será o valor mesclado do `currentState` e `optimisticValue`.
4848

49+
#### Retorna {/*returns*/}
4950

50-
#### Returns {/*returns*/}
51-
52-
* `optimisticState`: The resulting optimistic state. It is equal to `state` unless an action is pending, in which case it is equal to the value returned by `updateFn`.
53-
* `addOptimistic`: `addOptimistic` is the dispatching function to call when you have an optimistic update. It takes one argument, `optimisticValue`, of any type and will call the `updateFn` with `state` and `optimisticValue`.
51+
* `optimisticState`: O estado otimista resultante. É igual a `state`, a menos que uma ação esteja pendente, caso em que é igual ao valor retornado por `updateFn`.
52+
* `addOptimistic`: `addOptimistic` é a função de dispatch para chamar quando você tem uma atualização otimista. Ele recebe um argumento, `optimisticValue`, de qualquer tipo e chamará o `updateFn` com `state` e `optimisticValue`.
5453

5554
---
5655

57-
## Usage {/*usage*/}
56+
## Uso {/*usage*/}
5857

59-
### Optimistically updating forms {/*optimistically-updating-with-forms*/}
58+
### Atualizando formulários de forma otimista {/*optimistically-updating-with-forms*/}
6059

61-
The `useOptimistic` Hook provides a way to optimistically update the user interface before a background operation, like a network request, completes. In the context of forms, this technique helps to make apps feel more responsive. When a user submits a form, instead of waiting for the server's response to reflect the changes, the interface is immediately updated with the expected outcome.
60+
O Hook `useOptimistic` fornece uma maneira de atualizar a interface do usuário de forma otimista antes que uma operação em segundo plano, como uma requisição de rede, seja concluída. No contexto de formulários, essa técnica ajuda a tornar os aplicativos mais responsivos. Quando um usuário envia um formulário, em vez de esperar pela resposta do servidor para refletir as alterações, a interface é imediatamente atualizada com o resultado esperado.
6261

63-
For example, when a user types a message into the form and hits the "Send" button, the `useOptimistic` Hook allows the message to immediately appear in the list with a "Sending..." label, even before the message is actually sent to a server. This "optimistic" approach gives the impression of speed and responsiveness. The form then attempts to truly send the message in the background. Once the server confirms the message has been received, the "Sending..." label is removed.
62+
Por exemplo, quando um usuário digita uma mensagem no formulário e aperta o botão "Enviar", o Hook `useOptimistic` permite que a mensagem apareça imediatamente na lista com um rótulo "Enviando...", mesmo antes que a mensagem seja realmente enviada a um servidor. Essa abordagem "otimista" dá a impressão de velocidade e responsividade. O formulário tenta então enviar a mensagem de verdade em segundo plano. Depois que o servidor confirma que a mensagem foi recebida, o rótulo "Enviando..." é removido.
6463

6564
<Sandpack>
6665

67-
6866
```js src/App.js
6967
import { useOptimistic, useState, useRef } from "react";
7068
import { deliverMessage } from "./actions.js";
@@ -122,5 +120,4 @@ export async function deliverMessage(message) {
122120
}
123121
```
124122

125-
126-
</Sandpack>
123+
</Sandpack>

0 commit comments

Comments
 (0)