Skip to content

Commit 9c48ce2

Browse files
Translate forwardRef.md to Portuguese (#1058)
1 parent a3f3875 commit 9c48ce2

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/content/reference/react/forwardRef.md

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ title: forwardRef
44

55
<Deprecated>
66

7-
In React 19, `forwardRef` is no longer necessary. Pass `ref` as a prop instead.
7+
Em React 19, `forwardRef` não é mais necessário. Passe `ref` como uma prop em vez disso.
88

9-
`forwardRef` will deprecated in a future release. Learn more [here](/blog/2024/04/25/react-19#ref-as-a-prop).
9+
`forwardRef` será descontinuado em uma versão futura. Saiba mais [aqui](/blog/2024/04/25/react-19#ref-as-a-prop).
1010

1111
</Deprecated>
1212

1313
<Intro>
1414

15-
`forwardRef` lets your component expose a DOM node to parent component with a [ref.](/learn/manipulating-the-dom-with-refs)
15+
`forwardRef` permite que seu componente exponha um nó do DOM ao componente pai com um [ref.](/learn/manipulating-the-dom-with-refs)
1616

1717
```js
1818
const SomeComponent = forwardRef(render)
@@ -24,11 +24,11 @@ const SomeComponent = forwardRef(render)
2424

2525
---
2626

27-
## Reference {/*reference*/}
27+
## Referência {/*reference*/}
2828

2929
### `forwardRef(render)` {/*forwardref*/}
3030

31-
Call `forwardRef()` to let your component receive a ref and forward it to a child component:
31+
Chame `forwardRef()` para permitir que seu componente receba um ref e o encaminhe para um componente filho:
3232

3333
```js
3434
import { forwardRef } from 'react';
@@ -38,26 +38,26 @@ const MyInput = forwardRef(function MyInput(props, ref) {
3838
});
3939
```
4040

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

43-
#### Parameters {/*parameters*/}
43+
#### Parâmetros {/*parameters*/}
4444

45-
* `render`: The render function for your component. React calls this function with the props and `ref` that your component received from its parent. The JSX you return will be the output of your component.
45+
* `render`: A função de renderização para o seu componente. React chama esta função com as props e `ref` que seu componente recebeu de seu pai. O JSX que você retornar será a saída do seu componente.
4646

47-
#### Returns {/*returns*/}
47+
#### Retorna {/*returns*/}
4848

49-
`forwardRef` returns a React component that you can render in JSX. Unlike React components defined as plain functions, a component returned by `forwardRef` is also able to receive a `ref` prop.
49+
`forwardRef` retorna um componente React que você pode renderizar em JSX. Diferente dos componentes React definidos como funções simples, um componente retornado por `forwardRef` também é capaz de receber uma prop `ref`.
5050

51-
#### Caveats {/*caveats*/}
51+
#### Ressalvas {/*caveats*/}
5252

53-
* In Strict Mode, React will **call your render function twice** in order to [help you find accidental impurities.](/reference/react/useState#my-initializer-or-updater-function-runs-twice) This is development-only behavior and does not affect production. If your render function is pure (as it should be), this should not affect the logic of your component. The result from one of the calls will be ignored.
53+
* No Modo Estrito, React **chama sua função de renderização duas vezes** para [ajudá-lo a encontrar impurezas acidentais.](/reference/react/useState#my-initializer-or-updater-function-runs-twice) Este é um comportamento apenas para desenvolvimento e não afeta a produção. Se sua função de renderização for pura (como deveria ser), isso não deve afetar a lógica do seu componente. O resultado de uma das chamadas será ignorado.
5454

5555

5656
---
5757

58-
### `render` function {/*render-function*/}
58+
### Função `render` {/*render-function*/}
5959

60-
`forwardRef` accepts a render function as an argument. React calls this function with `props` and `ref`:
60+
`forwardRef` aceita uma função de renderização como um argumento. React chama essa função com `props` e `ref`:
6161

6262
```js
6363
const MyInput = forwardRef(function MyInput(props, ref) {
@@ -70,23 +70,23 @@ const MyInput = forwardRef(function MyInput(props, ref) {
7070
});
7171
```
7272

73-
#### Parameters {/*render-parameters*/}
73+
#### Parâmetros {/*render-parameters*/}
7474

75-
* `props`: The props passed by the parent component.
75+
* `props`: As props passadas pelo componente pai.
7676

77-
* `ref`: The `ref` attribute passed by the parent component. The `ref` can be an object or a function. If the parent component has not passed a ref, it will be `null`. You should either pass the `ref` you receive to another component, or pass it to [`useImperativeHandle`.](/reference/react/useImperativeHandle)
77+
* `ref`: O atributo `ref` passado pelo componente pai. O `ref` pode ser um objeto ou uma função. Se o componente pai não tiver passado um ref, ele será `null`. Você deve passar o `ref` que você recebe para outro componente, ou passá-lo para [`useImperativeHandle`.](/reference/react/useImperativeHandle)
7878

79-
#### Returns {/*render-returns*/}
79+
#### Retorna {/*render-returns*/}
8080

81-
`forwardRef` returns a React component that you can render in JSX. Unlike React components defined as plain functions, the component returned by `forwardRef` is able to take a `ref` prop.
81+
`forwardRef` retorna um componente React que você pode renderizar em JSX. Diferente dos componentes React definidos como funções simples, o componente retornado por `forwardRef` é capaz de receber uma prop `ref`.
8282

8383
---
8484

85-
## Usage {/*usage*/}
85+
## Uso {/*usage*/}
8686

87-
### Exposing a DOM node to the parent component {/*exposing-a-dom-node-to-the-parent-component*/}
87+
### Expondo um nó do DOM para o componente pai {/*exposing-a-dom-node-to-the-parent-component*/}
8888

89-
By default, each component's DOM nodes are private. However, sometimes it's useful to expose a DOM node to the parent--for example, to allow focusing it. To opt in, wrap your component definition into `forwardRef()`:
89+
Por padrão, os nós do DOM de cada componente são privados. No entanto, às vezes é útil expor um nó do DOM para o pai - por exemplo, para permitir focar nele. Para participar, envolva a definição do seu componente em `forwardRef()`:
9090

9191
```js {3,11}
9292
import { forwardRef } from 'react';
@@ -102,7 +102,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
102102
});
103103
```
104104

105-
You will receive a <CodeStep step={1}>ref</CodeStep> as the second argument after props. Pass it to the DOM node that you want to expose:
105+
Você receberá um <CodeStep step={1}>ref</CodeStep> como o segundo argumento após as props. Passe-o para o nó do DOM que você deseja expor:
106106

107107
```js {8} [[1, 3, "ref"], [1, 8, "ref", 30]]
108108
import { forwardRef } from 'react';
@@ -118,7 +118,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
118118
});
119119
```
120120

121-
This lets the parent `Form` component access the <CodeStep step={2}>`<input>` DOM node</CodeStep> exposed by `MyInput`:
121+
Isso permite que o componente `Form` pai acesse o <CodeStep step={2}>nó do DOM `</input>`</CodeStep> exposto por `MyInput`:
122122

123123
```js [[1, 2, "ref"], [1, 10, "ref", 41], [2, 5, "ref.current"]]
124124
function Form() {
@@ -139,15 +139,15 @@ function Form() {
139139
}
140140
```
141141

142-
This `Form` component [passes a ref](/reference/react/useRef#manipulating-the-dom-with-a-ref) to `MyInput`. The `MyInput` component *forwards* that ref to the `<input>` browser tag. As a result, the `Form` component can access that `<input>` DOM node and call [`focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on it.
142+
Este componente `Form` [passa um ref](/reference/react/useRef#manipulating-the-dom-with-a-ref) para `MyInput`. O componente `MyInput` *encaminha* aquele ref para a tag do navegador `<input>`. Como resultado, o componente `Form` pode acessar aquele nó do DOM `<input>` e chamar [`focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) nele.
143143

144-
Keep in mind that exposing a ref to the DOM node inside your component makes it harder to change your component's internals later. You will typically expose DOM nodes from reusable low-level components like buttons or text inputs, but you won't do it for application-level components like an avatar or a comment.
144+
Tenha em mente que expor um ref para o nó do DOM dentro do seu componente torna mais difícil alterar o funcionamento interno do seu componente mais tarde. Você tipicamente expõe nós do DOM de componentes reutilizáveis de baixo nível como botões ou entradas de texto, mas você não fará isso para componentes em nível de aplicação como um avatar ou um comentário.
145145

146-
<Recipes titleText="Examples of forwarding a ref">
146+
<Recipes titleText="Exemplos de encaminhamento de um ref">
147147

148-
#### Focusing a text input {/*focusing-a-text-input*/}
148+
#### Focando uma entrada de texto {/*focusing-a-text-input*/}
149149

150-
Clicking the button will focus the input. The `Form` component defines a ref and passes it to the `MyInput` component. The `MyInput` component forwards that ref to the browser `<input>`. This lets the `Form` component focus the `<input>`.
150+
Clicar no botão irá focar a entrada. O componente `Form` define um ref e o passa para o componente `MyInput`. O componente `MyInput` encaminha aquele ref para o `<input>` do navegador. Isso permite que o componente `Form` foque o `<input>`.
151151

152152
<Sandpack>
153153

@@ -199,9 +199,9 @@ input {
199199

200200
<Solution />
201201

202-
#### Playing and pausing a video {/*playing-and-pausing-a-video*/}
202+
#### Reproduzindo e pausando um vídeo {/*playing-and-pausing-a-video*/}
203203

204-
Clicking the button will call [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) and [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause) on a `<video>` DOM node. The `App` component defines a ref and passes it to the `MyVideoPlayer` component. The `MyVideoPlayer` component forwards that ref to the browser `<video>` node. This lets the `App` component play and pause the `<video>`.
204+
Clicar no botão irá chamar [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) e [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause) em um nó do DOM `<video>`. O componente `App` define um ref e o passa para o componente `MyVideoPlayer`. O componente `MyVideoPlayer` encaminha aquele ref para o nó `<video>` do navegador. Isso permite que o componente `App` reproduza e pause o `<video>`.
205205

206206
<Sandpack>
207207

@@ -260,9 +260,9 @@ button { margin-bottom: 10px; margin-right: 10px; }
260260

261261
---
262262

263-
### Forwarding a ref through multiple components {/*forwarding-a-ref-through-multiple-components*/}
263+
### Encaminhando um ref através de múltiplos componentes {/*forwarding-a-ref-through-multiple-components*/}
264264

265-
Instead of forwarding a `ref` to a DOM node, you can forward it to your own component like `MyInput`:
265+
Em vez de encaminhar um `ref` para um nó do DOM, você pode encaminhá-lo para seu próprio componente como `MyInput`:
266266

267267
```js {1,5}
268268
const FormField = forwardRef(function FormField(props, ref) {
@@ -276,7 +276,7 @@ const FormField = forwardRef(function FormField(props, ref) {
276276
});
277277
```
278278

279-
If that `MyInput` component forwards a ref to its `<input>`, a ref to `FormField` will give you that `<input>`:
279+
Se aquele componente `MyInput` encaminhar um ref para seu `<input>`, um ref para `FormField` lhe dará aquele `<input>`:
280280

281281
```js {2,5,10}
282282
function Form() {
@@ -297,7 +297,7 @@ function Form() {
297297
}
298298
```
299299

300-
The `Form` component defines a ref and passes it to `FormField`. The `FormField` component forwards that ref to `MyInput`, which forwards it to a browser `<input>` DOM node. This is how `Form` accesses that DOM node.
300+
O componente `Form` define um ref e o passa para `FormField`. O componente `FormField` encaminha aquele ref para `MyInput`, que o encaminha para um nó do DOM `<input>` do navegador. É assim que `Form` acessa aquele nó do DOM.
301301

302302

303303
<Sandpack>
@@ -375,9 +375,9 @@ input, button {
375375

376376
---
377377

378-
### Exposing an imperative handle instead of a DOM node {/*exposing-an-imperative-handle-instead-of-a-dom-node*/}
378+
### Expondo um manipulador imperativo em vez de um nó do DOM {/*exposing-an-imperative-handle-instead-of-a-dom-node*/}
379379

380-
Instead of exposing an entire DOM node, you can expose a custom object, called an *imperative handle,* with a more constrained set of methods. To do this, you'd need to define a separate ref to hold the DOM node:
380+
Em vez de expor um nó do DOM inteiro, você pode expor um objeto customizado, chamado *manipulador imperativo,* com um conjunto mais restrito de métodos. Para fazer isso, você precisaria definir um ref separado para manter o nó do DOM:
381381

382382
```js {2,6}
383383
const MyInput = forwardRef(function MyInput(props, ref) {
@@ -389,7 +389,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
389389
});
390390
```
391391

392-
Pass the `ref` you received to [`useImperativeHandle`](/reference/react/useImperativeHandle) and specify the value you want to expose to the `ref`:
392+
Passe o `ref` que você recebeu para [`useImperativeHandle`](/reference/react/useImperativeHandle) e especifique o valor que você deseja expor para o `ref`:
393393

394394
```js {6-15}
395395
import { forwardRef, useRef, useImperativeHandle } from 'react';
@@ -412,7 +412,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
412412
});
413413
```
414414

415-
If some component gets a ref to `MyInput`, it will only receive your `{ focus, scrollIntoView }` object instead of the DOM node. This lets you limit the information you expose about your DOM node to the minimum.
415+
Se algum componente receber um ref para `MyInput`, ele só receberá seu objeto `{ focus, scrollIntoView }` em vez do nó do DOM. Isso permite que você limite a informação que você expõe sobre o seu nó do DOM ao mínimo.
416416

417417
<Sandpack>
418418

@@ -425,7 +425,7 @@ export default function Form() {
425425

426426
function handleClick() {
427427
ref.current.focus();
428-
// This won't work because the DOM node isn't exposed:
428+
// Isso não vai funcionar porque o nó do DOM não está exposto:
429429
// ref.current.style.opacity = 0.5;
430430
}
431431

@@ -471,25 +471,25 @@ input {
471471

472472
</Sandpack>
473473

474-
[Read more about using imperative handles.](/reference/react/useImperativeHandle)
474+
[Leia mais sobre o uso de manipuladores imperativos.](/reference/react/useImperativeHandle)
475475

476476
<Pitfall>
477477

478-
**Do not overuse refs.** You should only use refs for *imperative* behaviors that you can't express as props: for example, scrolling to a node, focusing a node, triggering an animation, selecting text, and so on.
478+
**Não use demais refs.** Você deve usar refs apenas para comportamentos *imperativos* que você não pode expressar como props: por exemplo, rolar para um nó, focar em um nó, acionar uma animação, selecionar texto, e assim por diante.
479479

480-
**If you can express something as a prop, you should not use a ref.** For example, instead of exposing an imperative handle like `{ open, close }` from a `Modal` component, it is better to take `isOpen` as a prop like `<Modal isOpen={isOpen} />`. [Effects](/learn/synchronizing-with-effects) can help you expose imperative behaviors via props.
480+
**Se você pode expressar algo como uma prop, você não deve usar um ref.** Por exemplo, em vez de expor um manipulador imperativo como `{ open, close }` de um componente `Modal`, é melhor usar `isOpen` como uma prop como `<Modal isOpen={isOpen} />`. [Effects](/learn/synchronizing-with-effects) pode ajudá-lo a expor comportamentos imperativos via props.
481481

482482
</Pitfall>
483483

484484
---
485485

486-
## Troubleshooting {/*troubleshooting*/}
486+
## Solução de problemas {/*troubleshooting*/}
487487

488-
### My component is wrapped in `forwardRef`, but the `ref` to it is always `null` {/*my-component-is-wrapped-in-forwardref-but-the-ref-to-it-is-always-null*/}
488+
### Meu componente está encapsulado em `forwardRef`, mas o `ref` para ele é sempre `null` {/*my-component-is-wrapped-in-forwardref-but-the-ref-to-it-is-always-null*/}
489489

490-
This usually means that you forgot to actually use the `ref` that you received.
490+
Isso geralmente significa que você esqueceu de realmente usar o `ref` que você recebeu.
491491

492-
For example, this component doesn't do anything with its `ref`:
492+
Por exemplo, este componente não faz nada com o seu `ref`:
493493

494494
```js {1}
495495
const MyInput = forwardRef(function MyInput({ label }, ref) {
@@ -502,7 +502,7 @@ const MyInput = forwardRef(function MyInput({ label }, ref) {
502502
});
503503
```
504504

505-
To fix it, pass the `ref` down to a DOM node or another component that can accept a ref:
505+
Para corrigi-lo, passe o `ref` para um nó do DOM ou outro componente que pode aceitar um ref:
506506

507507
```js {1,5}
508508
const MyInput = forwardRef(function MyInput({ label }, ref) {
@@ -515,7 +515,7 @@ const MyInput = forwardRef(function MyInput({ label }, ref) {
515515
});
516516
```
517517

518-
The `ref` to `MyInput` could also be `null` if some of the logic is conditional:
518+
O `ref` para `MyInput` também pode ser `null` se alguma lógica for condicional:
519519

520520
```js {1,5}
521521
const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
@@ -528,7 +528,7 @@ const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
528528
});
529529
```
530530

531-
If `showInput` is `false`, then the ref won't be forwarded to any node, and a ref to `MyInput` will remain empty. This is particularly easy to miss if the condition is hidden inside another component, like `Panel` in this example:
531+
Se `showInput` for `false`, então o ref não será encaminhado para nenhum nó, e um ref para `MyInput` permanecerá vazio. Isso é particularmente fácil de perder se a condição estiver escondida dentro de outro componente, como `Panel` neste exemplo:
532532

533533
```js {5,7}
534534
const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
@@ -541,4 +541,4 @@ const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
541541
</label>
542542
);
543543
});
544-
```
544+
```

0 commit comments

Comments
 (0)