You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3942ced
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/react/useTransition.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ function SubmitButton({ submitAction }) {
99
99
100
100
`startTransition` não possui valor de retorno.
101
101
102
-
#### Caveats {/*starttransition-caveats*/}
102
+
#### Ressalvas {/*starttransition-caveats*/}
103
103
104
104
*`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.
105
105
@@ -199,8 +199,8 @@ export default function App({}) {
@@ -225,7 +225,7 @@ import { startTransition } from "react";
225
225
226
226
exportdefaultfunctionItem({action}) {
227
227
functionhandleChange(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.
229
229
startTransition(async () => {
230
230
awaitaction(event.target.value);
231
231
})
@@ -266,7 +266,7 @@ export default function Total({quantity, isPending}) {
266
266
```js src/api.js
267
267
exportasyncfunctionupdateQuantity(newQuantity) {
268
268
returnnewPromise((resolve, reject) => {
269
-
//Simulate a slow network request.
269
+
//Simula uma requisição de rede lenta.
270
270
setTimeout(() => {
271
271
resolve(newQuantity);
272
272
}, 2000);
@@ -303,14 +303,14 @@ export async function updateQuantity(newQuantity) {
303
303
304
304
</Sandpack>
305
305
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).
307
307
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:
-[Ações de `<form>`](/reference/react-dom/components/form)
311
+
-[Funções de Servidor](/reference/rsc/server-functions)
312
312
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.
314
314
315
315
<Solution />
316
316
@@ -348,7 +348,7 @@ export default function App({}) {
@@ -534,7 +534,7 @@ export default function Total({quantity, isPending}) {
534
534
```js src/api.js
535
535
exportasyncfunctionupdateQuantity(newQuantity) {
536
536
returnnewPromise((resolve, reject) => {
537
-
//Simulate a slow network request.
537
+
//Simula uma requisição de rede lenta.
538
538
setTimeout(() => {
539
539
resolve(newQuantity);
540
540
}, 2000);
@@ -571,7 +571,7 @@ export async function updateQuantity(newQuantity) {
571
571
572
572
</Sandpack>
573
573
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.
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.
744
744
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.
@@ -1831,7 +1831,7 @@ import {startTransition} from 'react';
1831
1831
1832
1832
exportdefaultfunctionItem({action}) {
1833
1833
functionhandleChange(e) {
1834
-
//Update the quantity in an Action.
1834
+
//Atualiza a quantidade em uma Ação.
1835
1835
startTransition(async () => {
1836
1836
awaitaction(e.target.value);
1837
1837
});
@@ -1887,7 +1887,7 @@ export async function updateQuantity(newName) {
1887
1887
setTimeout(() => {
1888
1888
firstRequest =true;
1889
1889
resolve(newName);
1890
-
//Simulate every other request being slower
1890
+
//Simula que uma a cada duas requisições é mais lenta
1891
1891
}, 1000);
1892
1892
} else {
1893
1893
setTimeout(() => {
@@ -1943,7 +1943,7 @@ Quando clicar várias vezes, é possível que as solicitações anteriores sejam
1943
1943
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.
1944
1944
1945
1945
1946
-
Example of`useActionState`handling execution order:
1946
+
Exemplo de`useActionState`tratando a ordem de execução:
1947
1947
1948
1948
<Sandpack>
1949
1949
@@ -1969,15 +1969,15 @@ import Item from "./Item";
1969
1969
importTotalfrom"./Total";
1970
1970
1971
1971
exportdefaultfunctionApp({}) {
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.
0 commit comments