Skip to content

Commit 449c9bf

Browse files
Adding translations to the findDOMNode API (#627)
* Adding translations to the findDOMNode API * Update beta/src/content/reference/react-dom/findDOMNode.md Keeping the links to other sections with their original text. Co-authored-by: Rainer Martinez <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Rainer Martinez <[email protected]>
1 parent cbe5f55 commit 449c9bf

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

beta/src/content/reference/react-dom/findDOMNode.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: findDOMNode
44

55
<Deprecated>
66

7-
This API will be removed in a future major version of React. [See the alternatives.](#alternatives)
7+
Esta API se eliminará en una futura versión mayor de React. [Ver las alternativas.](#alternatives)
88

99
</Deprecated>
1010

1111
<Intro>
1212

13-
`findDOMNode` finds the browser DOM node for a React [class component](/reference/react/Component) instance.
13+
`findDOMNode` encuentra el nodo DOM del navegador para una instancia de [componente de clase](/reference/react/Component) de React.
1414

1515
```js
1616
const domNode = findDOMNode(componentInstance)
@@ -22,46 +22,46 @@ const domNode = findDOMNode(componentInstance)
2222

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Referencia {/*reference*/}
2626

2727
### `findDOMNode(componentInstance)` {/*finddomnode*/}
2828

29-
Call `findDOMNode` to find the browser DOM node for a given React [class component](/reference/react/Component) instance.
29+
Llama a `findDOMNode` para encontrar el nodo DOM del navegador para una instancia dada de un [componente de clase](/reference/react/Component) de React.
3030

3131
```js
3232
import { findDOMNode } from 'react-dom';
3333

3434
const domNode = findDOMNode(componentInstance);
3535
```
3636

37-
[See more examples below.](#usage)
37+
[Consulta más ejemplos debajo.](#usage)
3838

39-
#### Parameters {/*parameters*/}
39+
#### Parámetros {/*parameters*/}
4040

41-
* `componentInstance`: An instance of the [`Component`](/reference/react/Component) subclass. For example, `this` inside a class component.
41+
* `componentInstance`: Una instancia de la subclase [`Componente`](/reference/react/Component). Por ejemplo, `this` dentro de un componente de clase.
4242

4343

4444
#### Returns {/*returns*/}
4545

46-
`findDOMNode` returns the first closest browser DOM node within the given `componentInstance`. When a component renders to `null`, or renders `false`, `findDOMNode` returns `null`. When a component renders to a string, `findDOMNode` returns a text DOM node containing that value.
46+
`findDOMNode` devuelve el primer nodo DOM del navegador más cercano dentro del `componentInstance` dado. Cuando un componente renderiza `null` o `false`, `findDOMNode` devuelve `null`. Cuando un componente renderiza un string, `findDOMNode` devuelve un nodo DOM de texto que contiene ese valor.
4747

48-
#### Caveats {/*caveats*/}
48+
#### Advertencias {/*caveats*/}
4949

50-
* A component may return an array or a [Fragment](/reference/react/Fragment) with multiple children. In that case `findDOMNode`, will return the DOM node corresponding to the first non-empty child.
50+
* Un componente puede devolver un array o un [Fragment](/reference/react/Fragment) con múltiples hijos. En este caso, `findDOMNode` devolverá el nodo DOM correspondiente al primer hijo no vacío.
5151

52-
* `findDOMNode` only works on mounted components (that is, components that have been placed in the DOM). If you try to call this on a component that has not been mounted yet (like calling `findDOMNode()` in `render()` on a component that has yet to be created), an exception will be thrown.
52+
* `findDOMNode` solo funciona en componentes montados (es decir, componentes que se han colocado en el DOM). Si intentas llamar a esto en un componente que aún no se ha montado (como llamar a `findDOMNode()` en `render()` en un componente que aún no se ha creado), se lanzará una excepción.
5353

54-
* `findDOMNode` only returns the result at the time of your call. If a child component renders a different node later, there is no way for you to be notified of this change.
54+
* `findDOMNode` solo devuelve el resultado en el momento de tu llamada. Si un componente hijo representa un nodo diferente más tarde, no hay manera de que se te notifique de este cambio.
5555

56-
* `findDOMNode` accepts a class component instance, so it can't be used with function components.
56+
* `findDOMNode` acepta una instancia de componente de clase, por lo que no se puede usar con componentes de función.
5757

5858
---
5959

60-
## Usage {/*usage*/}
60+
## Uso {/*usage*/}
6161

62-
### Finding the root DOM node of a class component {/*finding-the-root-dom-node-of-a-class-component*/}
62+
### Encontrar el nodo DOM raíz de un componente de clase {/*finding-the-root-dom-node-of-a-class-component*/}
6363

64-
Call `findDOMNode` with a [class component](/reference/react/Component) instance (usually, `this`) to find the DOM node it has rendered.
64+
Llama a `findDOMNode` con una instancia de un [componente de clase](/reference/react/Component) (por lo general, `this`) para encontrar el nodo DOM que ha renderizado.
6565

6666
```js {3}
6767
class AutoselectingInput extends Component {
@@ -71,12 +71,12 @@ class AutoselectingInput extends Component {
7171
}
7272

7373
render() {
74-
return <input defaultValue="Hello" />
74+
return <input defaultValue="Hola" />
7575
}
7676
}
7777
```
7878

79-
Here, the `input` variable will be set to the `<input>` DOM element. This lets you do something with it. For example, when clicking "Show example" below mounts the input, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) selects all text in the input:
79+
Aquí, la variable `input` se establecerá en el elemento DOM `<input>`. Esto te permite hacer algo con él. Por ejemplo, al hacer clic en "Mostrar ejemplo" a continuación, se monta el input, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) selecciona todo el texto del input:
8080

8181
<Sandpack>
8282

@@ -89,7 +89,7 @@ export default function App() {
8989
return (
9090
<>
9191
<button onClick={() => setShow(true)}>
92-
Show example
92+
Mostrar ejemplo
9393
</button>
9494
<hr />
9595
{show && <AutoselectingInput />}
@@ -109,7 +109,7 @@ class AutoselectingInput extends Component {
109109
}
110110

111111
render() {
112-
return <input defaultValue="Hello" />
112+
return <input defaultValue="Hola" />
113113
}
114114
}
115115

@@ -120,11 +120,11 @@ export default AutoselectingInput;
120120

121121
---
122122

123-
## Alternatives {/*alternatives*/}
123+
## Alternativas {/*alternatives*/}
124124

125-
### Reading component's own DOM node from a ref {/*reading-components-own-dom-node-from-a-ref*/}
125+
### Leyendo el nodo DOM propio de un componente a través de una referencia {/*reading-components-own-dom-node-from-a-ref*/}
126126

127-
Code using `findDOMNode` is fragile because the connection between the JSX node and the code manipulating the corresponding DOM node is not explicit. For example, try wrapping `<input />` from this example into a `<div>`:
127+
El código que utiliza `findDOMNode` es frágil debido a que la conexión entre el nodo JSX y el código que manipula el nodo DOM correspondiente no es explícita. Por ejemplo, prueba a envolver `<input />` de este ejemplo en un `<div>`:
128128

129129
<Sandpack>
130130

@@ -137,7 +137,7 @@ export default function App() {
137137
return (
138138
<>
139139
<button onClick={() => setShow(true)}>
140-
Show example
140+
Mostrar ejemplo
141141
</button>
142142
<hr />
143143
{show && <AutoselectingInput />}
@@ -156,7 +156,7 @@ class AutoselectingInput extends Component {
156156
input.select()
157157
}
158158
render() {
159-
return <input defaultValue="Hello" />
159+
return <input defaultValue="Hola" />
160160
}
161161
}
162162

@@ -165,9 +165,9 @@ export default AutoselectingInput;
165165

166166
</Sandpack>
167167

168-
This will break the code because now, `findDOMNode(this)` finds the `<div>` DOM node, but the code expects an `<input>` DOM node. To avoid these kinds of problems, use [`createRef`](/reference/react/createRef) to manage a specific DOM node.
168+
Esto romperá el código porque ahora, `findDOMNode(this)` encuentra el nodo DOM `<div>`, pero el código espera un nodo DOM `<input>`. Para evitar este tipo de problemas, utiliza [`createRef`](/reference/react/createRef) para gestionar un nodo DOM específico.
169169

170-
In this example, `findDOMNode` is no longer used. Instead, `inputRef = createRef(null)` is defined as an instance field on the class. To read the DOM node from it, you can use `this.inputRef.current`. To attach it to the JSX, you render `<input ref={this.inputRef} />`. You have connected the code using the DOM node to its JSX:
170+
En este ejemplo, ya no se usa `findDOMNode`. En su lugar, se define `inputRef = createRef(null)` como un campo de instancia en la clase. Para leer el nodo DOM de él, puedes usar `this.inputRef.current`. Para adjuntarlo al JSX, renderiza `<input ref={this.inputRef} />`. Has conectado el código que usa el nodo DOM con su JSX:
171171

172172
<Sandpack>
173173

@@ -180,7 +180,7 @@ export default function App() {
180180
return (
181181
<>
182182
<button onClick={() => setShow(true)}>
183-
Show example
183+
Mostrar ejemplo
184184
</button>
185185
<hr />
186186
{show && <AutoselectingInput />}
@@ -202,7 +202,7 @@ class AutoselectingInput extends Component {
202202

203203
render() {
204204
return (
205-
<input ref={this.inputRef} defaultValue="Hello" />
205+
<input ref={this.inputRef} defaultValue="Hola" />
206206
);
207207
}
208208
}
@@ -212,7 +212,7 @@ export default AutoselectingInput;
212212

213213
</Sandpack>
214214

215-
In modern React without class components, the equivalent code would call [`useRef`](/reference/react/useRef) instead:
215+
En React moderno sin componentes de clase, el código equivalente llamaría a [`useRef`](/reference/react/useRef) en su lugar:
216216

217217
<Sandpack>
218218

@@ -225,7 +225,7 @@ export default function App() {
225225
return (
226226
<>
227227
<button onClick={() => setShow(true)}>
228-
Show example
228+
Mostrar ejemplo
229229
</button>
230230
<hr />
231231
{show && <AutoselectingInput />}
@@ -245,19 +245,19 @@ export default function AutoselectingInput() {
245245
input.select();
246246
}, []);
247247

248-
return <input ref={inputRef} defaultValue="Hello" />
248+
return <input ref={inputRef} defaultValue="Hola" />
249249
}
250250
```
251251

252252
</Sandpack>
253253

254-
[Read more about manipulating the DOM with refs.](/learn/manipulating-the-dom-with-refs)
254+
[Lee más sobre cómo manipular el DOM con refs.](/learn/manipulating-the-dom-with-refs)
255255

256256
---
257257

258-
### Reading a child component's DOM node from a forwarded ref {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
258+
### Leer el nodo DOM de un componente hijo desde una ref reenviada {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
259259

260-
In this example, `findDOMNode(this)` finds a DOM node that belongs to another component. The `AutoselectingInput` renders `MyInput`, which is your own component that renders a browser `<input>`.
260+
En este ejemplo, `findDOMNode(this)` encuentra un nodo DOM que pertenece a otro componente. El `AutoselectingInput` renderiza `MyInput`, que es tu propio componente que representa una entrada del navegador `<input>`.
261261

262262
<Sandpack>
263263

@@ -270,7 +270,7 @@ export default function App() {
270270
return (
271271
<>
272272
<button onClick={() => setShow(true)}>
273-
Show example
273+
Mostrar ejemplo
274274
</button>
275275
<hr />
276276
{show && <AutoselectingInput />}
@@ -299,20 +299,20 @@ export default AutoselectingInput;
299299

300300
```js MyInput.js
301301
export default function MyInput() {
302-
return <input defaultValue="Hello" />;
302+
return <input defaultValue="Hola" />;
303303
}
304304
```
305305

306306
</Sandpack>
307307

308-
Notice that calling `findDOMNode(this)` inside `AutoselectingInput` still gives you the DOM `<input>`--even though the JSX for this `<input>` is hidden inside the `MyInput` component. This seems convenient for the above example, but it leads to fragile code. Imagine that you wanted to edit `MyInput` later and add a wrapper `<div>` around it. This would break the code of `AutoselectingInput` (which expects to find an `<input>` DOM node).
308+
Ten en cuenta que llamar a `findDOMNode(this)` dentro de `AutoselectingInput` aún te da el nodo DOM `<input>`, aunque el JSX para este `<input>` está oculto dentro del componente `MyInput`. Esto parece conveniente para el ejemplo anterior, pero conduce a un código frágil. Imagínate que deseas editar `MyInput` más tarde y agregar un elemento `<div>` envuelto alrededor de él. Esto rompería el código de `AutoselectingInput` (que espera encontrar un nodo DOM `<input>`).
309309

310-
To replace `findDOMNode` in this example, the two components need to coordinate:
310+
Para reemplazar `findDOMNode` en este ejemplo, los dos componentes deben coordinarse:
311311

312-
1. `AutoSelectingInput` should declare a ref, like [in the earlier example](#reading-components-own-dom-node-from-a-ref), and pass it to `<MyInput>`.
313-
2. `MyInput` should be declared with [`forwardRef`](/reference/react/forwardRef) to read the passed ref, and pass it down to the `<input>` node.
312+
1. `AutoSelectingInput` debe declarar una ref, como [en el ejemplo anterior](#reading-components-own-dom-node-from-a-ref), y pasarlo a `<MyInput>`.
313+
2. `MyInput` debe ser declarado con [`forwardRef`](/reference/react/forwardRef) para leer la ref pasado y pasarla hacia abajo al nodo `<input>`.
314314

315-
This version does that, so it no longer needs `findDOMNode`:
315+
Esta versión hace eso, por lo que ya no necesita `findDOMNode`:
316316

317317
<Sandpack>
318318

@@ -325,7 +325,7 @@ export default function App() {
325325
return (
326326
<>
327327
<button onClick={() => setShow(true)}>
328-
Show example
328+
Mostrar ejemplo
329329
</button>
330330
<hr />
331331
{show && <AutoselectingInput />}
@@ -360,15 +360,15 @@ export default AutoselectingInput;
360360
import { forwardRef } from 'react';
361361

362362
const MyInput = forwardRef(function MyInput(props, ref) {
363-
return <input ref={ref} defaultValue="Hello" />;
363+
return <input ref={ref} defaultValue="Hola" />;
364364
});
365365

366366
export default MyInput;
367367
```
368368

369369
</Sandpack>
370370

371-
Here is how this code would look like with function components instead of classes:
371+
Así es como se vería este código con componentes de función en lugar de clases:
372372

373373
<Sandpack>
374374

@@ -381,7 +381,7 @@ export default function App() {
381381
return (
382382
<>
383383
<button onClick={() => setShow(true)}>
384-
Show example
384+
Mostrar ejemplo
385385
</button>
386386
<hr />
387387
{show && <AutoselectingInput />}
@@ -402,15 +402,15 @@ export default function AutoselectingInput() {
402402
input.select();
403403
}, []);
404404

405-
return <MyInput ref={inputRef} defaultValue="Hello" />
405+
return <MyInput ref={inputRef} defaultValue="Hola" />
406406
}
407407
```
408408

409409
```js MyInput.js
410410
import { forwardRef } from 'react';
411411

412412
const MyInput = forwardRef(function MyInput(props, ref) {
413-
return <input ref={ref} defaultValue="Hello" />;
413+
return <input ref={ref} defaultValue="Hola" />;
414414
});
415415

416416
export default MyInput;
@@ -420,16 +420,16 @@ export default MyInput;
420420

421421
---
422422

423-
### Adding a wrapper `<div>` element {/*adding-a-wrapper-div-element*/}
423+
### Agregar un elemento envoltorio `<div>` {/*adding-a-wrapper-div-element*/}
424424

425-
Sometimes a component needs to know the position and size of its children. This makes it tempting to find the children with `findDOMNode(this)`, and then use DOM methods like [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) for measurements.
425+
A veces, un componente necesita conocer la posición y el tamaño de sus hijos. Esto hace tentador encontrar a los hijos con `findDOMNode(this)`, y luego usar métodos DOM como [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) para las mediciones.
426426

427-
There is currently no direct equivalent for this use case, which is why `findDOMNode` is deprecated but is not yet removed completely from React. In the meantime, you can try rendering a wrapper `<div>` node around the content as a workaround, and getting a ref to that node. However, extra wrappers can sometimes break styling.
427+
Actualmente, no hay un equivalente directo para este uso, por lo que `findDOMNode` está en desuso pero aún no se ha eliminado completamente de React. Mientras tanto, puedes intentar renderizar un nodo envoltorio `<div>` alrededor del contenido como una solución temporal y obtener una referencia a ese nodo. Sin embargo, los envoltorios adicionales a veces pueden romper el estilo.
428428

429429
```js
430430
<div ref={someRef}>
431431
{children}
432432
</div>
433433
```
434434

435-
This also applies to focusing and scrolling to arbitrary children.
435+
Esto también se aplica al enfoque y desplazamiento a hijos arbitrarios

0 commit comments

Comments
 (0)