diff --git a/src/content/reference/react/useTransition.md b/src/content/reference/react/useTransition.md index 87bc4da265..df59f6babc 100644 --- a/src/content/reference/react/useTransition.md +++ b/src/content/reference/react/useTransition.md @@ -99,7 +99,7 @@ function SubmitButton({ submitAction }) { `startTransition` não possui valor de retorno. -#### Caveats {/*starttransition-caveats*/} +#### Ressalvas {/*starttransition-caveats*/} * `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. @@ -199,8 +199,8 @@ export default function App({}) { const [isPending, startTransition] = useTransition(); const updateQuantityAction = async newQuantity => { - // To access the pending state of a transition, - // call startTransition again. + // Para acessar o state pendente de uma transição, + // chame startTransition novamente. startTransition(async () => { const savedQuantity = await updateQuantity(newQuantity); startTransition(() => { @@ -225,7 +225,7 @@ import { startTransition } from "react"; export default function Item({action}) { function handleChange(event) { - // To expose an action prop, await the callback in startTransition. + // Para expor uma prop action, use await no callback dentro de startTransition. startTransition(async () => { await action(event.target.value); }) @@ -266,7 +266,7 @@ export default function Total({quantity, isPending}) { ```js src/api.js export async function updateQuantity(newQuantity) { return new Promise((resolve, reject) => { - // Simulate a slow network request. + // Simula uma requisição de rede lenta. setTimeout(() => { resolve(newQuantity); }, 2000); @@ -303,14 +303,14 @@ export async function updateQuantity(newQuantity) { -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). +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). -For common use cases, React provides built-in abstractions such as: +Para casos de uso comuns, o React fornece abstrações embutidas, como: - [`useActionState`](/reference/react/useActionState) -- [`
` actions](/reference/react-dom/components/form) -- [Server Functions](/reference/rsc/server-functions) +- [Ações de ``](/reference/react-dom/components/form) +- [Funções de Servidor](/reference/rsc/server-functions) -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. +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. @@ -348,7 +348,7 @@ export default function App({}) { const [isPending, setIsPending] = useState(false); const onUpdateQuantity = async newQuantity => { - // Manually set the isPending State. + // Define o state isPending manualmente. setIsPending(true); const savedQuantity = await updateQuantity(newQuantity); setIsPending(false); @@ -408,7 +408,7 @@ export default function Total({quantity, isPending}) { ```js src/api.js export async function updateQuantity(newQuantity) { return new Promise((resolve, reject) => { - // Simulate a slow network request. + // Simula uma requisição de rede lenta. setTimeout(() => { resolve(newQuantity); }, 2000); @@ -445,7 +445,7 @@ export async function updateQuantity(newQuantity) { -A common solution to this problem is to prevent the user from making changes while the quantity is updating: +Uma solução comum para esse problema é impedir que o usuário faça alterações enquanto a quantidade está sendo atualizada: @@ -476,7 +476,7 @@ export default function App({}) { const onUpdateQuantity = async event => { const newQuantity = event.target.value; - // Manually set the isPending state. + // Define o state isPending manualmente. setIsPending(true); const savedQuantity = await updateQuantity(newQuantity); setIsPending(false); @@ -534,7 +534,7 @@ export default function Total({quantity, isPending}) { ```js src/api.js export async function updateQuantity(newQuantity) { return new Promise((resolve, reject) => { - // Simulate a slow network request. + // Simula uma requisição de rede lenta. setTimeout(() => { resolve(newQuantity); }, 2000); @@ -571,7 +571,7 @@ export async function updateQuantity(newQuantity) { -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. +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. @@ -594,8 +594,8 @@ export default function TabButton({ action, children, isActive }) { return (