Skip to content

Commit 768e637

Browse files
committed
docs: translate findDOMNode page to Bahasa Indonesia
1 parent e3f28a4 commit 768e637

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

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

+37-38
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: findDOMNode
44

55
<Deprecated>
66

7-
API ini akan dihapus pada mayor versi berikutnya. [See the alternatives.](#alternatives)
7+
API ini akan dihapus pada versi mayor React yang akan datang. [Lihat alternatif lainnya.](#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` mencari simpul DOM peramban untuk *instance* dari [*class component*](/reference/react/Component) React
1414

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

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Referensi {/*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+
Panggil `findDOMNode` untuk mencari simpul DOM peramban pada *instance* dari [*class component*](/reference/react/Component) React yang diberikan.
3030

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

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

37-
[See more examples below.](#usage)
37+
[Lihat contoh lainnya di bawah ini.](#usage)
3838

39-
#### Parameters {/*parameters*/}
39+
#### Parameter {/*parameters*/}
4040

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.
4242

43+
#### Pengembalian {/*returns*/}
4344

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.
4546

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*/}
4748

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.
4950

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.
5152

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.
5354

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*.
5756

5857
---
5958

60-
## Usage {/*usage*/}
59+
## Penggunaan {/*usage*/}
6160

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*/}
6362

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.
6564

6665
```js {3}
6766
class AutoselectingInput extends Component {
@@ -76,7 +75,7 @@ class AutoselectingInput extends Component {
7675
}
7776
```
7877

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:
8079

8180
<Sandpack>
8281

@@ -120,11 +119,11 @@ export default AutoselectingInput;
120119

121120
---
122121

123-
## Alternatives {/*alternatives*/}
122+
## Alternatif {/*alternatives*/}
124123

125-
### 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*/}
126125

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>`:
128127

129128
<Sandpack>
130129

@@ -165,9 +164,9 @@ export default AutoselectingInput;
165164

166165
</Sandpack>
167166

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.
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.
169168

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:
171170

172171
<Sandpack>
173172

@@ -212,7 +211,7 @@ export default AutoselectingInput;
212211

213212
</Sandpack>
214213

215-
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:
216215

217216
<Sandpack>
218217

@@ -251,13 +250,13 @@ export default function AutoselectingInput() {
251250

252251
</Sandpack>
253252

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)
255254

256255
---
257256

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*/}
259258

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.
261260

262261
<Sandpack>
263262

@@ -305,14 +304,14 @@ export default function MyInput() {
305304

306305
</Sandpack>
307306

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>`).
309308

310-
To replace `findDOMNode` in this example, the two components need to coordinate:
309+
Untuk mengganti `findDOMNode` dalam contoh ini, kedua komponen harus berkoordinasi:
311310

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>`.
314313

315-
This version does that, so it no longer needs `findDOMNode`:
314+
Contoh di bawah ini melakukan hal tersebut, sehingga tidak lagi membutuhkan `findDOMNode`:
316315

317316
<Sandpack>
318317

@@ -368,7 +367,7 @@ export default MyInput;
368367

369368
</Sandpack>
370369

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*:
372371

373372
<Sandpack>
374373

@@ -420,16 +419,16 @@ export default MyInput;
420419

421420
---
422421

423-
### Adding a wrapper `<div>` element {/*adding-a-wrapper-div-element*/}
422+
### Menambahkan elemen pembungkus `<div>` {/*adding-a-wrapper-div-element*/}
424423

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.
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.
426425

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*.
428427

429428
```js
430429
<div ref={someRef}>
431430
{children}
432431
</div>
433432
```
434433

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

Comments
 (0)