Skip to content

Commit 27dd842

Browse files
committed
docs: translation for forwardRef (#352)
1 parent 1cdc601 commit 27dd842

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

src/content/reference/react/forwardRef.md

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

55
<Intro>
66

7-
`forwardRef` lets your component expose a DOM node to parent component with a [ref.](/learn/manipulating-the-dom-with-refs)
7+
`forwardRef` memungkinkan Anda mengekspos sebuah *DOM node* sebagai sebuah [ref](/learn/manipulating-the-dom-with-refs) kepada induknya.
88

99
```js
1010
const SomeComponent = forwardRef(render)
@@ -16,11 +16,11 @@ const SomeComponent = forwardRef(render)
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## Referensi {/*reference*/}
2020

2121
### `forwardRef(render)` {/*forwardref*/}
2222

23-
Call `forwardRef()` to let your component receive a ref and forward it to a child component:
23+
Panggil fungsi `forwardRef()` untuk membiarkan komponen Anda menerima *ref* dan meneruskannya ke komponen anak:
2424

2525
```js
2626
import { forwardRef } from 'react';
@@ -30,26 +30,26 @@ const MyInput = forwardRef(function MyInput(props, ref) {
3030
});
3131
```
3232

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

3535
#### Parameters {/*parameters*/}
3636

37-
* `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.
37+
* `render`: Fungsi *render* untuk komponen Anda. React memanggil fungsi ini dengan *props* dan `ref` yang diterima komponen Anda dari induknya. JSX yang Anda kembalikan akan menjadi keluaran dari komponen Anda.
3838

39-
#### Returns {/*returns*/}
39+
#### Mengembalikan {/*returns*/}
4040

41-
`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.
41+
`forwardRef` mengembalikan komponen React yang dapat Anda *render* di JSX. Tidak seperti komponen React yang didefinisikan sebagai fungsi biasa, komponen yang dikembalikan oleh `forwardRef` juga dapat menerima *prop* `ref`.
4242

43-
#### Caveats {/*caveats*/}
43+
#### Peringatan {/*caveats*/}
4444

45-
* In Strict Mode, React will **call your render function twice** in order to [help you find accidental impurities.](#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.
45+
* Dalam Mode Ketat, React akan **memanggil fungsi *render* Anda dua kali** untuk [membantu Anda menemukan ketidakmurnian yang tidak disengaja.](#my-initializer-or-updater-function-runs-twice) Ini adalah perilaku khusus pengembangan dan tidak mempengaruhi produksi. Jika fungsi *render* Anda murni (sebagaimana mestinya), hal ini tidak akan mempengaruhi logika komponen Anda. Hasil dari salah satu pemanggilan akan diabaikan.
4646

4747

4848
---
4949

5050
### `render` function {/*render-function*/}
5151

52-
`forwardRef` accepts a render function as an argument. React calls this function with `props` and `ref`:
52+
`forwardRef` menerima fungsi *render* sebagai argumen. React memanggil fungsi ini dengan `props` dan `ref`:
5353

5454
```js
5555
const MyInput = forwardRef(function MyInput(props, ref) {
@@ -64,21 +64,21 @@ const MyInput = forwardRef(function MyInput(props, ref) {
6464

6565
#### Parameters {/*render-parameters*/}
6666

67-
* `props`: The props passed by the parent component.
67+
* `props`: *props* yang dioperkan oleh komponen induk.
6868

69-
* `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)
69+
* `ref`: Atribut `ref` yang dioper oleh komponen induk. `ref` dapat berupa objek atau fungsi. Jika komponen induk tidak mengoper *ref*, maka akan menjadi `null`. Anda harus mengoper `ref` yang Anda terima ke komponen lain, atau mengopernya ke [`useImperativeHandle`.](/reference/react/useImperativeHandle)
7070

7171
#### Returns {/*render-returns*/}
7272

73-
`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.
73+
`forwardRef` mengembalikan komponen React yang dapat Anda *render* di JSX. Tidak seperti komponen React yang didefinisikan sebagai fungsi biasa, komponen yang dikembalikan oleh `forwardRef` dapat mengambil sebuah *prop* `ref`.
7474

7575
---
7676

77-
## Usage {/*usage*/}
77+
## Penggunaan {/*usage*/}
7878

79-
### Exposing a DOM node to the parent component {/*exposing-a-dom-node-to-the-parent-component*/}
79+
### Mengekspos DOM node ke komponen induk {/*exposing-a-dom-node-to-the-parent-component*/}
8080

81-
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()`:
81+
Secara *default*, setiap *DOM nodes* komponen bersifat privat. Namun, terkadang berguna untuk mengekspos *DOM node* ke induknya - misalnya, untuk memungkinkan pemfokusan. Untuk ikut serta, bungkus definisi komponen Anda ke dalam `forwardRef()`:
8282

8383
```js {3,11}
8484
import { forwardRef } from 'react';
@@ -94,7 +94,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
9494
});
9595
```
9696

97-
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:
97+
Anda akan menerima <CodeStep step={1}>ref</CodeStep> sebagai argumen kedua setelah props. Berikan ke *DOM node* yang ingin Anda ekspos:
9898

9999
```js {8} [[1, 3, "ref"], [1, 8, "ref", 30]]
100100
import { forwardRef } from 'react';
@@ -110,7 +110,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
110110
});
111111
```
112112

113-
This lets the parent `Form` component access the <CodeStep step={2}>`<input>` DOM node</CodeStep> exposed by `MyInput`:
113+
Hal ini memungkinkan komponen `Form` induk mengakses <CodeStep step={2}>`<input>` DOM node</CodeStep> yang diekspos oleh `MyInput`:
114114

115115
```js [[1, 2, "ref"], [1, 10, "ref", 41], [2, 5, "ref.current"]]
116116
function Form() {
@@ -131,15 +131,16 @@ function Form() {
131131
}
132132
```
133133

134-
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.
134+
Komponen `MyInput` meneruskan *ref* tersebut ke tag peramban `<input>`. Hasilnya, komponen `Form` dapat mengakses *DOM node* `<input>` tersebut dan memanggil fungsi [`focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) di atasnya.
135+
136+
Perlu diingat bahwa mengekspos *ref* ke *DOM node* di dalam komponen Anda akan mempersulit untuk mengubah internal komponen Anda di kemudian hari. Anda biasanya akan mengekspos *DOM node* dari komponen tingkat rendah yang dapat digunakan kembali seperti tombol atau input teks, tetapi Anda tidak akan melakukannya untuk komponen tingkat aplikasi seperti avatar atau komentar.
135137

136-
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.
137138

138139
<Recipes title="Examples of forwarding a ref">
139140

140-
#### Focusing a text input {/*focusing-a-text-input*/}
141+
#### Memfokuskan input teks {/*focusing-a-text-input*/}
141142

142-
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>`.
143+
Mengeklik tombol akan memfokuskan input. Komponen `Form` mendefinisikan sebuah ref dan meneruskannya ke komponen `MyInput`. Komponen `MyInput` meneruskan *ref* tersebut ke tag peramban `<input>`. Hal ini memungkinkan komponen `Form` memfokuskan `<input>`.
143144

144145
<Sandpack>
145146

@@ -191,9 +192,9 @@ input {
191192

192193
<Solution />
193194

194-
#### Playing and pausing a video {/*playing-and-pausing-a-video*/}
195+
#### Memutar dan menjeda video {/*playing-and-pausing-a-video*/}
195196

196-
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>`.
197+
Mengeklik tombol akan memanggil [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) dan [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause) pada *DOM node* `<video>`. Komponen `Aplikasi` mendefinisikan sebuah ref dan meneruskannya ke komponen `MyVideoPlayer`. Komponen `MyVideoPlayer` meneruskan *ref* tersebut ke *node* `<video>` pada peramban. Hal ini memungkinkan komponen `Aplikasi` memainkan dan menjeda `<video>`.
197198

198199
<Sandpack>
199200

@@ -252,9 +253,9 @@ button { margin-bottom: 10px; margin-right: 10px; }
252253

253254
---
254255

255-
### Forwarding a ref through multiple components {/*forwarding-a-ref-through-multiple-components*/}
256+
### Meneruskan ref melalui beberapa komponen {/*forwarding-a-ref-through-multiple-components*/}
256257

257-
Instead of forwarding a `ref` to a DOM node, you can forward it to your own component like `MyInput`:
258+
Alih-alih meneruskan `ref` ke *DOM node*, Anda bisa meneruskannya ke komponen Anda sendiri seperti `MyInput`:
258259

259260
```js {1,5}
260261
const FormField = forwardRef(function FormField(props, ref) {
@@ -268,7 +269,7 @@ const FormField = forwardRef(function FormField(props, ref) {
268269
});
269270
```
270271

271-
If that `MyInput` component forwards a ref to its `<input>`, a ref to `FormField` will give you that `<input>`:
272+
Jika komponen `MyInput` meneruskan sebuah *ref* ke `<input>`, sebuah *ref* ke `FormField` akan memberi Anda `<input>` tersebut:
272273

273274
```js {2,5,10}
274275
function Form() {
@@ -289,8 +290,7 @@ function Form() {
289290
}
290291
```
291292

292-
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.
293-
293+
Komponen `Form` mendefinisikan sebuah *ref* dan meneruskannya ke `FormField`. Komponen `FormField` meneruskan *ref* tersebut ke `MyInput`, yang meneruskannya ke *DOM node* `<input>` peramban. Beginilah cara `Form` mengakses *DOM node* tersebut.
294294

295295
<Sandpack>
296296

@@ -367,9 +367,10 @@ input, button {
367367

368368
---
369369

370-
### Exposing an imperative handle instead of a DOM node {/*exposing-an-imperative-handle-instead-of-a-dom-node*/}
370+
### Mengekspos penanganan imperatif daripada DOM node {/*exposing-an-imperative-handle-instead-of-a-dom-node*/}
371+
372+
Daripada mengekspos seluruh *DOM node*, Anda dapat mengekspos objek khusus, yang disebut *imperative handle,* dengan sekumpulan metode yang lebih terbatas. Untuk melakukan ini, Anda harus mendefinisikan *ref* terpisah untuk menampung *DOM node*:
371373

372-
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:
373374

374375
```js {2,6}
375376
const MyInput = forwardRef(function MyInput(props, ref) {
@@ -381,7 +382,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
381382
});
382383
```
383384

384-
Pass the `ref` you received to [`useImperativeHandle`](/reference/react/useImperativeHandle) and specify the value you want to expose to the `ref`:
385+
Berikan `ref` yang Anda terima ke [`useImperativeHandle`](/reference/react/useImperativeHandle) dan tentukan nilai yang ingin Anda ekspos ke `ref`:
385386

386387
```js {6-15}
387388
import { forwardRef, useRef, useImperativeHandle } from 'react';
@@ -404,7 +405,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
404405
});
405406
```
406407

407-
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.
408+
Jika beberapa komponen mendapatkan referensi ke `MyInput`, komponen tersebut hanya akan menerima objek `{ focus, scrollIntoView }`, bukan *DOM node*. Hal ini memungkinkan Anda membatasi informasi yang Anda paparkan tentang *DOM node* seminimal mungkin.
408409

409410
<Sandpack>
410411

@@ -463,25 +464,25 @@ input {
463464

464465
</Sandpack>
465466

466-
[Read more about using imperative handles.](/reference/react/useImperativeHandle)
467+
[Baca lebih lanjut tentang menggunakan penanganan imperatif.](/reference/react/useImperativeHandle)
467468

468469
<Pitfall>
469470

470-
**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.
471+
**Jangan terlalu sering menggunakan refs.** Anda hanya boleh menggunakan *refs* untuk perilaku *imperatif* yang tidak dapat Anda ungkapkan sebagai *props*: misalnya, menggulir ke sebuah *node*, memfokuskan sebuah *node*, memicu sebuah animasi, memilih teks, dan sebagainya.
471472

472-
**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.
473+
**Jika Anda dapat mengekspresikan sesuatu sebagai *prop*, Anda tidak boleh menggunakan *ref*.** Sebagai contoh, daripada mengekspos penanganan imperatif seperti `{ open, close }` dari komponen `Modal`, lebih baik menggunakan `isOpen` sebagai *prop* seperti `<Modal isOpen={isOpen} />`. [Effects](/learn/synchronizing-with-effects) dapat membantu Anda mengekspos perilaku imperatif melalui *props*.
473474

474475
</Pitfall>
475476

476477
---
477478

478-
## Troubleshooting {/*troubleshooting*/}
479+
## Pemecahan Masalah {/*troubleshooting*/}
479480

480-
### 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*/}
481+
### Komponen saya dibungkus dengan `forwardRef`, tetapi `ref` ke komponen tersebut selalu `null` {/*my-component-is-wrapped-in-forwardref-but-the-ref-to-it-is-always-null*/}
481482

482-
This usually means that you forgot to actually use the `ref` that you received.
483+
Hal ini biasanya berarti bahwa Anda lupa menggunakan `ref` yang Anda terima.
483484

484-
For example, this component doesn't do anything with its `ref`:
485+
Sebagai contoh, komponen ini tidak melakukan apa pun dengan `ref`-nya:
485486

486487
```js {1}
487488
const MyInput = forwardRef(function MyInput({ label }, ref) {
@@ -494,7 +495,7 @@ const MyInput = forwardRef(function MyInput({ label }, ref) {
494495
});
495496
```
496497

497-
To fix it, pass the `ref` down to a DOM node or another component that can accept a ref:
498+
Untuk memperbaikinya, berikan `ref` ke *DOM node* atau komponen lain yang dapat menerima *ref*:
498499

499500
```js {1,5}
500501
const MyInput = forwardRef(function MyInput({ label }, ref) {
@@ -507,7 +508,7 @@ const MyInput = forwardRef(function MyInput({ label }, ref) {
507508
});
508509
```
509510

510-
The `ref` to `MyInput` could also be `null` if some of the logic is conditional:
511+
`ref` ke Komponen `MyInput` juga dapat menjadi `null` jika beberapa logika bersyarat:
511512

512513
```js {1,5}
513514
const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
@@ -520,7 +521,7 @@ const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
520521
});
521522
```
522523

523-
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:
524+
Jika `showInput` bernilai `false`, maka *ref* tidak akan diteruskan ke *node* mana pun, dan *ref* ke `MyInput` akan tetap kosong. Hal ini sangat mudah terlewatkan jika kondisi tersebut tersembunyi di dalam komponen lain, seperti `Panel` pada contoh ini:
524525

525526
```js {5,7}
526527
const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {

0 commit comments

Comments
 (0)