Skip to content

Commit 3942ced

Browse files
committed
Tradução das seções restantes de useTransition.md para Português (Brasil)
1 parent ac83623 commit 3942ced

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

‎src/content/reference/react/useTransition.md‎

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function SubmitButton({ submitAction }) {
9999

100100
`startTransition` não possui valor de retorno.
101101

102-
#### Caveats {/*starttransition-caveats*/}
102+
#### Ressalvas {/*starttransition-caveats*/}
103103

104104
* `useTransition` é um Hook, portanto, deve ser chamado dentro de componentes ou Hooks personalizados. Se você precisar iniciar uma transição em outro lugar (por exemplo, a partir de uma biblioteca de dados), chame a função independente [`startTransition`](/reference/react/startTransition) em vez disso.
105105

@@ -199,8 +199,8 @@ export default function App({}) {
199199
const [isPending, startTransition] = useTransition();
200200

201201
const updateQuantityAction = async newQuantity => {
202-
// To access the pending state of a transition,
203-
// call startTransition again.
202+
// Para acessar o estado pendente de uma transição,
203+
// chame startTransition novamente.
204204
startTransition(async () => {
205205
const savedQuantity = await updateQuantity(newQuantity);
206206
startTransition(() => {
@@ -225,7 +225,7 @@ import { startTransition } from "react";
225225

226226
export default function Item({action}) {
227227
function handleChange(event) {
228-
// To expose an action prop, await the callback in startTransition.
228+
// Para expor uma prop action, use await no callback dentro de startTransition.
229229
startTransition(async () => {
230230
await action(event.target.value);
231231
})
@@ -266,7 +266,7 @@ export default function Total({quantity, isPending}) {
266266
```js src/api.js
267267
export async function updateQuantity(newQuantity) {
268268
return new Promise((resolve, reject) => {
269-
// Simulate a slow network request.
269+
// Simula uma requisição de rede lenta.
270270
setTimeout(() => {
271271
resolve(newQuantity);
272272
}, 2000);
@@ -303,14 +303,14 @@ export async function updateQuantity(newQuantity) {
303303

304304
</Sandpack>
305305

306-
This is a basic example to demonstrate how Actions work, but this example does not handle requests completing out of order. When updating the quantity multiple times, it's possible for the previous requests to finish after later requests causing the quantity to update out of order. This is a known limitation that we will fix in the future (see [Troubleshooting](#my-state-updates-in-transitions-are-out-of-order) below).
306+
Este é um exemplo básico para demonstrar como as Ações funcionam, mas ele não trata requisições que terminam fora de ordem. Ao atualizar a quantidade várias vezes, é possível que as requisições anteriores terminem depois das posteriores, fazendo a quantidade ser atualizada fora de ordem. Esta é uma limitação conhecida que vamos corrigir no futuro (veja [Solução de problemas](#my-state-updates-in-transitions-are-out-of-order) abaixo).
307307

308-
For common use cases, React provides built-in abstractions such as:
308+
Para casos de uso comuns, o React fornece abstrações embutidas, como:
309309
- [`useActionState`](/reference/react/useActionState)
310-
- [`<form>` actions](/reference/react-dom/components/form)
311-
- [Server Functions](/reference/rsc/server-functions)
310+
- [Ações de `<form>`](/reference/react-dom/components/form)
311+
- [Funções de Servidor](/reference/rsc/server-functions)
312312

313-
These solutions handle request ordering for you. When using Transitions to build your own custom hooks or libraries that manage async state transitions, you have greater control over the request ordering, but you must handle it yourself.
313+
Essas soluções tratam a ordem das requisições por você. Ao usar Transições para construir os seus próprios Hooks personalizados ou bibliotecas que gerenciam transições de estado assíncronas, você tem mais controle sobre a ordem das requisições, mas precisa tratá-la você mesmo.
314314

315315
<Solution />
316316

@@ -348,7 +348,7 @@ export default function App({}) {
348348
const [isPending, setIsPending] = useState(false);
349349

350350
const onUpdateQuantity = async newQuantity => {
351-
// Manually set the isPending State.
351+
// Define o estado isPending manualmente.
352352
setIsPending(true);
353353
const savedQuantity = await updateQuantity(newQuantity);
354354
setIsPending(false);
@@ -408,7 +408,7 @@ export default function Total({quantity, isPending}) {
408408
```js src/api.js
409409
export async function updateQuantity(newQuantity) {
410410
return new Promise((resolve, reject) => {
411-
// Simulate a slow network request.
411+
// Simula uma requisição de rede lenta.
412412
setTimeout(() => {
413413
resolve(newQuantity);
414414
}, 2000);
@@ -445,7 +445,7 @@ export async function updateQuantity(newQuantity) {
445445

446446
</Sandpack>
447447

448-
A common solution to this problem is to prevent the user from making changes while the quantity is updating:
448+
Uma solução comum para esse problema é impedir que o usuário faça alterações enquanto a quantidade está sendo atualizada:
449449

450450
<Sandpack>
451451

@@ -476,7 +476,7 @@ export default function App({}) {
476476

477477
const onUpdateQuantity = async event => {
478478
const newQuantity = event.target.value;
479-
// Manually set the isPending state.
479+
// Define o estado isPending manualmente.
480480
setIsPending(true);
481481
const savedQuantity = await updateQuantity(newQuantity);
482482
setIsPending(false);
@@ -534,7 +534,7 @@ export default function Total({quantity, isPending}) {
534534
```js src/api.js
535535
export async function updateQuantity(newQuantity) {
536536
return new Promise((resolve, reject) => {
537-
// Simulate a slow network request.
537+
// Simula uma requisição de rede lenta.
538538
setTimeout(() => {
539539
resolve(newQuantity);
540540
}, 2000);
@@ -571,7 +571,7 @@ export async function updateQuantity(newQuantity) {
571571

572572
</Sandpack>
573573

574-
This solution makes the app feel slow, because the user must wait each time they update the quantity. It's possible to add more complex handling manually to allow the user to interact with the UI while the quantity is updating, but Actions handle this case with a straight-forward built-in API.
574+
Essa solução deixa o app lento, porque o usuário precisa esperar toda vez que atualiza a quantidade. É possível adicionar manualmente um tratamento mais complexo para permitir que o usuário interaja com a UI enquanto a quantidade está sendo atualizada, mas as Ações tratam esse caso com uma API embutida e direta.
575575

576576
<Solution />
577577

@@ -594,8 +594,8 @@ export default function TabButton({ action, children, isActive }) {
594594
return (
595595
<button onClick={() => {
596596
startTransition(async () => {
597-
// await the action that's passed in.
598-
// This allows it to be either sync or async.
597+
// usa await na action recebida.
598+
// Isso permite que ela seja síncrona ou assíncrona.
599599
await action();
600600
});
601601
}}>
@@ -661,8 +661,8 @@ export default function TabButton({ action, children, isActive }) {
661661
return (
662662
<button onClick={async () => {
663663
startTransition(async () => {
664-
// await the action that's passed in.
665-
// This allows it to be either sync or async.
664+
// usa await na action recebida.
665+
// Isso permite que ela seja síncrona ou assíncrona.
666666
await action();
667667
});
668668
}}>
@@ -740,9 +740,9 @@ b { display: inline-block; margin-right: 10px; }
740740

741741
<Note>
742742

743-
When exposing an `action` prop from a component, you should `await` it inside the transition.
743+
Ao expor uma prop `action` a partir de um componente, você deve usar `await` nela dentro da transição.
744744

745-
This allows the `action` callback to be either synchronous or asynchronous without requiring an additional `startTransition` to wrap the `await` in the action.
745+
Isso permite que o callback `action` seja síncrono ou assíncrono, sem exigir um `startTransition` adicional para envolver o `await` na ação.
746746

747747
</Note>
748748

@@ -1213,7 +1213,7 @@ b { display: inline-block; margin-right: 10px; }
12131213
12141214
</Sandpack>
12151215
1216-
[Read more about using Transitions with Suspense.](/reference/react/Suspense#preventing-already-revealed-content-from-hiding)
1216+
[Leia mais sobre como usar Transições com Suspense.](/reference/react/Suspense#preventing-already-revealed-content-from-hiding)
12171217
12181218
<Note>
12191219
@@ -1586,8 +1586,8 @@ function AddCommentButton() {
15861586
disabled={pending}
15871587
onClick={() => {
15881588
startTransition(() => {
1589-
// Intentionally not passing a comment
1590-
// so error gets thrown
1589+
// Intencionalmente não passa um comentário
1590+
// para que o erro seja lançado
15911591
addComment();
15921592
});
15931593
}}
@@ -1702,7 +1702,7 @@ Quando você usa `await` dentro de uma função `startTransition`, as atualizaç
17021702
```js
17031703
startTransition(async () => {
17041704
await someAsyncFunction();
1705-
// ❌ Not using startTransition after await
1705+
// ❌ Sem usar startTransition depois do await
17061706
setPage('/about');
17071707
});
17081708
```
@@ -1712,7 +1712,7 @@ No entanto, isso funciona em vez disso:
17121712
```js
17131713
startTransition(async () => {
17141714
await someAsyncFunction();
1715-
// ✅ Using startTransition *after* await
1715+
// ✅ Usando startTransition *depois* do await
17161716
startTransition(() => {
17171717
setPage('/about');
17181718
});
@@ -1798,14 +1798,14 @@ import Total from "./Total";
17981798
export default function App({}) {
17991799
const [quantity, setQuantity] = useState(1);
18001800
const [isPending, startTransition] = useTransition();
1801-
// Store the actual quantity in separate state to show the mismatch.
1801+
// Guarda a quantidade real em um estado separado para mostrar a divergência.
18021802
const [clientQuantity, setClientQuantity] = useState(1);
18031803

18041804
const updateQuantityAction = newQuantity => {
18051805
setClientQuantity(newQuantity);
18061806

1807-
// Access the pending state of the transition,
1808-
// by wrapping in startTransition again.
1807+
// Acessa o estado pendente da transição,
1808+
// envolvendo em startTransition novamente.
18091809
startTransition(async () => {
18101810
const savedQuantity = await updateQuantity(newQuantity);
18111811
startTransition(() => {
@@ -1831,7 +1831,7 @@ import {startTransition} from 'react';
18311831

18321832
export default function Item({action}) {
18331833
function handleChange(e) {
1834-
// Update the quantity in an Action.
1834+
// Atualiza a quantidade em uma Ação.
18351835
startTransition(async () => {
18361836
await action(e.target.value);
18371837
});
@@ -1887,7 +1887,7 @@ export async function updateQuantity(newName) {
18871887
setTimeout(() => {
18881888
firstRequest = true;
18891889
resolve(newName);
1890-
// Simulate every other request being slower
1890+
// Simula que uma a cada duas requisições é mais lenta
18911891
}, 1000);
18921892
} else {
18931893
setTimeout(() => {
@@ -1943,7 +1943,7 @@ Quando clicar várias vezes, é possível que as solicitações anteriores sejam
19431943
Isso é esperado, porque Ações dentro de uma Transição não garantem a ordem de execução. Para casos de uso comuns, o React fornece abstrações de nível superior como [`useActionState`](/reference/react/useActionState) e ações de [`<form>`](/reference/react-dom/components/form) que lidam com a ordenação para você. Para casos de uso avançados, você precisará implementar sua própria lógica de fila e abortar para lidar com isso.
19441944
19451945
1946-
Example of `useActionState` handling execution order:
1946+
Exemplo de `useActionState` tratando a ordem de execução:
19471947
19481948
<Sandpack>
19491949
@@ -1969,15 +1969,15 @@ import Item from "./Item";
19691969
import Total from "./Total";
19701970

19711971
export default function App({}) {
1972-
// Store the actual quantity in separate state to show the mismatch.
1972+
// Guarda a quantidade real em um estado separado para mostrar a divergência.
19731973
const [clientQuantity, setClientQuantity] = useState(1);
19741974
const [quantity, updateQuantityAction, isPending] = useActionState(
19751975
async (prevState, payload) => {
19761976
setClientQuantity(payload);
19771977
const savedQuantity = await updateQuantity(payload);
1978-
return savedQuantity; // Return the new quantity to update the state
1978+
return savedQuantity; // Retorna a nova quantidade para atualizar o estado
19791979
},
1980-
1 // Initial quantity
1980+
1 // Quantidade inicial
19811981
);
19821982

19831983
return (
@@ -1997,7 +1997,7 @@ import {startTransition} from 'react';
19971997

19981998
export default function Item({action}) {
19991999
function handleChange(e) {
2000-
// Update the quantity in an Action.
2000+
// Atualiza a quantidade em uma Ação.
20012001
startTransition(() => {
20022002
action(e.target.value);
20032003
});
@@ -2053,7 +2053,7 @@ export async function updateQuantity(newName) {
20532053
setTimeout(() => {
20542054
firstRequest = true;
20552055
resolve(newName);
2056-
// Simulate every other request being slower
2056+
// Simula que uma a cada duas requisições é mais lenta
20572057
}, 1000);
20582058
} else {
20592059
setTimeout(() => {

0 commit comments

Comments
 (0)