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
Call`findDOMNode`to find the browser DOM node for a given React [class component](/reference/react/Component)instance.
29
+
Panggil`findDOMNode`untuk mencari simpul DOM peramban pada *instance* dari [*class component*](/reference/react/Component)React yang diberikan.
30
30
31
31
```js
32
32
import { findDOMNode } from'react-dom';
33
33
34
34
constdomNode=findDOMNode(componentInstance);
35
35
```
36
36
37
-
[See more examples below.](#usage)
37
+
[Lihat contoh lainnya di bawah ini.](#usage)
38
38
39
-
#### Parameters {/*parameters*/}
39
+
#### Parameter {/*parameters*/}
40
40
41
-
*`componentInstance`: An instance of the [`Component`](/reference/react/Component) subclass. For example, `this`inside a class component.
41
+
`componentInstance`: *Instance* dari subkelas [`Component`](/reference/react/Component). Misalnya, `this`di dalam komponen kelas.
42
42
43
+
#### Pengembalian {/*returns*/}
43
44
44
-
#### Returns {/*returns*/}
45
+
`findDOMNode` mengembalikan simpul DOM peramban pertama yang terdekat dalam `componentInstance` yang diberikan. Ketika komponen di-*render* menjadi `null`, atau di-*render* menjadi `false`, `findDOMNode` mengembalikan `null`. Ketika komponen di-*render* menjadi string, `findDOMNode` mengembalikan simpul DOM teks yang berisi nilai tersebut.
45
46
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.
47
+
#### Catatan Penting {/*caveats*/}
47
48
48
-
#### Caveats {/*caveats*/}
49
+
* Sebuah komponen dapat mengembalikan senarai atau [Fragment](/reference/react/Fragment) dengan beberapa *child*. Dalam hal ini `findDOMNode`, akan mengembalikan simpul DOM yang berhubungan dengan *child* pertama yang tidak kosong.
49
50
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.
51
+
*`findDOMNode` hanya bekerja pada komponen yang sudah terpasang (yaitu komponen yang sudah ditempatkan di DOM). Jika Anda mencoba memanggil ini pada komponen yang belum terpasang (seperti memanggil `findDOMNode()` dalam `render()` pada komponen yang belum dibuat), sebuah *exception* akan dilemparkan.
51
52
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.
53
+
*`findDOMNode`hanya mengembalikan hasil pada saat pemanggilan. Jika komponen *child* merender simpul yang nantinya berbeda, tidak ada cara untuk memberitahu Anda tentang perubahan ini.
53
54
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.
55
-
56
-
*`findDOMNode` accepts a class component instance, so it can't be used with function components.
55
+
*`findDOMNode` menerima instance komponen kelas, sehingga tidak dapat digunakan dengan *function component*.
57
56
58
57
---
59
58
60
-
## Usage {/*usage*/}
59
+
## Penggunaan {/*usage*/}
61
60
62
-
### Finding the root DOM node of a class component {/*finding-the-root-dom-node-of-a-class-component*/}
61
+
### Menemukan simpul DOM akar dari komponen kelas {/*finding-the-root-dom-node-of-a-class-component*/}
63
62
64
-
Call`findDOMNode`with a [class component](/reference/react/Component)instance (usually, `this`) to find the DOM node it has rendered.
63
+
Panggil`findDOMNode`dengan sebuah *instance* dari [class component](/reference/react/Component)(biasanya, `this`) untuk menemukan simpul DOM yang telah di-render.
65
64
66
65
```js {3}
67
66
classAutoselectingInputextendsComponent {
@@ -76,7 +75,7 @@ class AutoselectingInput extends Component {
76
75
}
77
76
```
78
77
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:
78
+
Di sini, variabel`input`akan disetel ke elemen DOM `<input>`. Hal ini memungkinkan Anda melakukan sesuatu dengannya. Sebagai contoh, ketika mengklik "Tampilkan contoh" di bawah ini untuk memasang input, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select)akan memilih semua teks di dalam input:
### Reading component's own DOM node from a ref {/*reading-components-own-dom-node-from-a-ref*/}
124
+
### Membaca simpul DOM komponen itu sendiri dari sebuah ref {/*reading-components-own-dom-node-from-a-ref*/}
126
125
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 this `<input />`into a`<div>`:
126
+
Kode yang menggunakan `findDOMNode`mudah rusak karena hubungan antara node JSX dan kode yang memanipulasi node DOM yang sesuai tidak eksplisit. Sebagai contoh, cobalah membungkus `<input />`menjadi`<div>`:
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.
167
+
Hal ini akan merusak kode karena sekarang, `findDOMNode(this)`menemukan simpul DOM `<div>`, tetapi kode mengharapkan simpul DOM`<input>`. Untuk menghindari masalah seperti ini, gunakan[`createRef`](/reference/react/createRef)untuk mengelola simpul DOM tertentu.
169
168
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} />`. This connects the code using the DOM node to its JSX:
169
+
Pada contoh ini, `findDOMNode`tidak lagi digunakan. Sebagai gantinya, `inputRef = createRef(null)`didefinisikan sebagai sebuah field instance pada kelas. Untuk membaca simpul DOM darinya, Anda bisa menggunakan`this.inputRef.current`. Untuk melampirkannya ke JSX, Anda me-*render*`<input ref = {this.inputRef} />`. Ini menghubungkan kode yang menggunakan simpul DOM ke JSX:
In modern React without class components, the equivalent code would call[`useRef`](/reference/react/useRef)instead:
214
+
Pada React modern tanpa *class components*, kode yang setara akan memanggil[`useRef`](/reference/react/useRef)sebagai gantinya:
216
215
217
216
<Sandpack>
218
217
@@ -251,13 +250,13 @@ export default function AutoselectingInput() {
251
250
252
251
</Sandpack>
253
252
254
-
[Read more about manipulating the DOM with refs.](/learn/manipulating-the-dom-with-refs)
253
+
[Baca lebih lanjut tentang memanipulasi DOM dengan *refs*.](/learn/manipulating-the-dom-with-refs)
255
254
256
255
---
257
256
258
-
### Reading a child component's DOM node from a forwarded ref {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
257
+
### Membaca simpul *child*DOM komponen dari ref yang diteruskan {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
259
258
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>`.
259
+
Pada contoh ini, `findDOMNode(this)`menemukan simpul DOM yang dimiliki oleh komponen lain. `AutoselectingInput`me-*render*`MyInput`, yang merupakan komponen Anda sendiri yang me-*render*`<input>` pada browser.
261
260
262
261
<Sandpack>
263
262
@@ -305,14 +304,14 @@ export default function MyInput() {
305
304
306
305
</Sandpack>
307
306
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>`).
307
+
Perhatikan bahwa memanggil`findDOMNode(this)`di dalam `AutoselectingInput`masih memberikan Anda DOM `<input>`, meskipun JSX untuk `<input>`ini disembunyikan di dalam komponen `MyInput`. Hal ini tampak mudah untuk contoh di atas, tetapi akan menyebabkan kode yang rapuh. Bayangkan Anda ingin mengubah `MyInput`nanti dan membungkus dengan `<div>`di sekelilingnya. Hal ini akan merusak kode `AutoselectingInput` (yang mengharapkan untuk menemukan`<input>`).
309
308
310
-
To replace`findDOMNode`in this example, the two components need to coordinate:
309
+
Untuk mengganti`findDOMNode`dalam contoh ini, kedua komponen harus berkoordinasi:
311
310
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 take that ref and forward it down to the `<input>` node.
311
+
1.`AutoSelectingInput`harus mendeklarasikan sebuah ref, seperti [pada contoh sebelumnya](#membaca-komponen-memiliki-simpul-dom-dari-ref), dan mengopernya ke`<MyInput>`.
312
+
2.`MyInput`harus dideklarasikan dengan [`forwardRef`](/reference/react/forwardRef)untuk mengambil ref tersebut dan meneruskannya ke simpul `<input>`.
314
313
315
-
This version does that, so it no longer needs`findDOMNode`:
314
+
Contoh di bawah ini melakukan hal tersebut, sehingga tidak lagi membutuhkan`findDOMNode`:
316
315
317
316
<Sandpack>
318
317
@@ -368,7 +367,7 @@ export default MyInput;
368
367
369
368
</Sandpack>
370
369
371
-
Here is how this code would look like with function components instead of classes:
370
+
Berikut ini adalah contoh kode jika kode tersebut menggunakan *function components*, bukan *class components*:
372
371
373
372
<Sandpack>
374
373
@@ -420,16 +419,16 @@ export default MyInput;
420
419
421
420
---
422
421
423
-
### Adding a wrapper`<div>` element {/*adding-a-wrapper-div-element*/}
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.
424
+
Terkadang sebuah komponen perlu mengetahui posisi dan ukuran anak-anaknya. Hal ini membuat Anda tertarik untuk mencari *child*-nya dengan`findDOMNode(this)`, dan kemudian menggunakan metode DOM seperti [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect)untuk mendapatkan informasi ukuran.
426
425
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 break styling.
426
+
Saat ini tidak ada solusi langsung untuk kasus penggunaan ini, itulah mengapa `findDOMNode`sudah di-*deprecate* tetapi belum dihapus sepenuhnya dari React. Untuk sementara ini, Anda dapat mencoba me-*render* simpul pembungkus`<div>`di sekitar konten sebagai solusi, dan mendapatkan ref ke simpul tersebut. Namun perlu diketahui bahwa pembungkus tambahan dapat merusak *styling*.
428
427
429
428
```js
430
429
<div ref={someRef}>
431
430
{children}
432
431
</div>
433
432
```
434
433
435
-
This also applies to focusing and scrolling to arbitrary children.
434
+
Hal ini juga berlaku untuk pemfokusan dan *scrolling* ke sembarang *children*.
0 commit comments