Skip to content

Commit 091a062

Browse files
authored
wip translation
1 parent f70576c commit 091a062

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/content/reference/react/createRef.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: createRef
44

55
<Pitfall>
66

7-
`createRef` is mostly used for [class components.](/reference/react/Component) Function components typically rely on [`useRef`](/reference/react/useRef) instead.
7+
`createRef` kebanyakan digunakan untuk [komponen kelas.](/reference/react/Component) sedangkan komponen fungsional biasanya mengandalkan [`useRef`](/reference/react/useRef).
88

99
</Pitfall>
1010

1111
<Intro>
1212

13-
`createRef` creates a [ref](/learn/referencing-values-with-refs) object which can contain arbitrary value.
13+
`createRef` membuat sebuah objek [*ref*](/learn/referencing-values-with-refs) yang menyimpan nilai apapun.
1414

1515
```js
1616
class MyInput extends Component {
@@ -25,11 +25,11 @@ class MyInput extends Component {
2525

2626
---
2727

28-
## Reference {/*reference*/}
28+
## Referensi {/*reference*/}
2929

3030
### `createRef()` {/*createref*/}
3131

32-
Call `createRef` to declare a [ref](/learn/referencing-values-with-refs) inside a [class component.](/reference/react/Component)
32+
Panggil `createRef` untuk mendeklarasikan sebuah [*ref*](/learn/referencing-values-with-refs) di dalam sebuah [komponen kelas.](/reference/react/Component)
3333

3434
```js
3535
import { createRef, Component } from 'react';
@@ -40,31 +40,31 @@ class MyComponent extends Component {
4040
// ...
4141
```
4242
43-
[See more examples below.](#usage)
43+
[Lihat contoh lebih banyak di bawah.](#usage)
4444
45-
#### Parameters {/*parameters*/}
45+
#### Parameter {/*parameters*/}
4646
47-
`createRef` takes no parameters.
47+
`createRef` tidak memerlukan parameter.
4848
49-
#### Returns {/*returns*/}
49+
#### Kembalian {/*returns*/}
5050
51-
`createRef` returns an object with a single property:
51+
`createRef` mengembalikan sebuah objek dengan properti tunggal:
5252
53-
* `current`: Initially, it's set to the `null`. You can later set it to something else. If you pass the ref object to React as a `ref` attribute to a JSX node, React will set its `current` property.
53+
* `current`: Awalnya, bernilai `null`. Anda dapat menggantinya dengan nilai lain kemudian. Jika Anda mengoper objek *ref* ke React sebagai sebuah atribut `ref` di dalam simpul JSX, React akan menetapkannya sebagai properti `current`.
5454
5555
#### Caveats {/*caveats*/}
5656
57-
* `createRef` always returns a *different* object. It's equivalent to writing `{ current: null }` yourself.
58-
* In a function component, you probably want [`useRef`](/reference/react/useRef) instead which always returns the same object.
59-
* `const ref = useRef()` is equivalent to `const [ref, _] = useState(() => createRef(null))`.
57+
* `createRef` selalu mengembalikan objek yang berbeda. Sama halnya dengan menulis `{ current: null }` manual.
58+
* Dalam komponen fungsional, Anda mungkin menginginkan [`useRef`](/reference/react/useRef) yang selalu mengembalikan obyek yang sama.
59+
* `const ref = useRef()` sama dengan `const [ref, _] = useState(() => createRef(null))`.
6060
6161
---
6262
63-
## Usage {/*usage*/}
63+
## Penggunaan {/*usage*/}
6464
65-
### Declaring a ref in a class component {/*declaring-a-ref-in-a-class-component*/}
65+
### Mendeklarasikan sebuah ref di dalam komponen kelas {/*declaring-a-ref-in-a-class-component*/}
6666
67-
To declare a ref inside a [class component,](/reference/react/Component) call `createRef` and assign its result to a class field:
67+
Untuk mendeklarasikan *ref* di dalam sebuah [komponen kelas,](/reference/react/Component) panggil `createRef` dan tetapkan hasilnya ke anggota (*field*) kelas:
6868
6969
```js {4}
7070
import { Component, createRef } from 'react';
@@ -76,7 +76,7 @@ class Form extends Component {
7676
}
7777
```
7878
79-
If you now pass `ref={this.inputRef}` to an `<input>` in your JSX, React will populate `this.inputRef.current` with the input DOM node. For example, here is how you make a button that focuses the input:
79+
Jika Anda mengoper `ref={this.inputRef}` ke sebuah `<input>` di dalam JSX Anda, React akan menempatkan input simpul DOM ke `this.inputRef.current`. Ini Contohnya bagaimana Anda membuat tombol yang memfokuskan ke input:
8080
8181
<Sandpack>
8282
@@ -107,17 +107,16 @@ export default class Form extends Component {
107107
108108
<Pitfall>
109109
110-
`createRef` is mostly used for [class components.](/reference/react/Component) Function components typically rely on [`useRef`](/reference/react/useRef) instead.
111-
110+
`createRef` kebanyakan digunakan untuk [komponen kelas.](/reference/react/Component) sedangkan komponen fungsional biasanya mengandalkan [`useRef`](/reference/react/useRef).
112111
</Pitfall>
113112
114113
---
115114
116-
## Alternatives {/*alternatives*/}
115+
## Alternatif {/*alternatives*/}
117116
118-
### Migrating from a class with `createRef` to a function with `useRef` {/*migrating-from-a-class-with-createref-to-a-function-with-useref*/}
117+
### Migrasi dari sebuah kelas dengan `createRef` ke fungsi dengan `useRef` {/*migrating-from-a-class-with-createref-to-a-function-with-useref*/}
119118
120-
We recommend using function components instead of [class components](/reference/react/Component) in new code. If you have some existing class components using `createRef`, here is how you can convert them. This is the original code:
119+
Kami merekomendasikan untuk menggunakan komponen fungsional dari pada [komponen kelas](/reference/react/Component) pada kode baru. Jika Anda memiliki komponen kelas yang menggunakan `createRef`, ini cara bagaimana mengubahnya. Ini merupakan kode awal:
121120
122121
<Sandpack>
123122
@@ -146,7 +145,7 @@ export default class Form extends Component {
146145
147146
</Sandpack>
148147
149-
When you [convert this component from a class to a function,](/reference/react/Component#alternatives) replace calls to `createRef` with calls to [`useRef`:](/reference/react/useRef)
148+
Saat Anda [mengubah komponen ini dari kelas ke fungsi,](/reference/react/Component#alternatives) ganti pemanggilan `createRef` dengan [`useRef`:](/reference/react/useRef)
150149
151150
<Sandpack>
152151

0 commit comments

Comments
 (0)