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
Copy file name to clipboardExpand all lines: src/content/reference/react/PureComponent.md
+17-17Lines changed: 17 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@ title: PureComponent
4
4
5
5
<Pitfall>
6
6
7
-
We recommend defining components as functions instead of classes. [See how to migrate.](#alternatives)
7
+
Kami menyarankan untuk membuat komponen sebagai fungsi, bukan kelas. [Lihat cara migrasinya.](#alternatives)
8
8
9
9
</Pitfall>
10
10
11
11
<Intro>
12
12
13
-
`PureComponent`is similar to [`Component`](/reference/react/Component)but it skips re-renders for same props and state. Class components are still supported by React, but we don't recommend using them in new code.
13
+
`PureComponent`mirip dengan [`Component`](/reference/react/Component)tetapi melewatkan proses *render* ulang untuk props dan state yang sama. Komponen kelas masih didukung oleh React, tetapi kami tidak menyarankan untuk menggunakannya dalam kode baru.
14
14
15
15
```js
16
16
classGreetingextendsPureComponent {
@@ -26,11 +26,11 @@ class Greeting extends PureComponent {
26
26
27
27
---
28
28
29
-
## Reference {/*reference*/}
29
+
## Referensi {/*reference*/}
30
30
31
31
### `PureComponent` {/*purecomponent*/}
32
32
33
-
To skip re-rendering a class component for same props and state, extend`PureComponent` instead of[`Component`:](/reference/react/Component)
33
+
Untuk melewatkan *render* ulang sebuah komponen kelas untuk props dan state yang sama, perluas`PureComponent`, bukan[`Component`:](/reference/react/Component)
34
34
35
35
```js
36
36
import { PureComponent } from'react';
@@ -42,18 +42,18 @@ class Greeting extends PureComponent {
42
42
}
43
43
```
44
44
45
-
`PureComponent`is a subclass of `Component`and supports [all the`Component` APIs.](/reference/react/Component#reference)Extending`PureComponent`is equivalent to defining a custom[`shouldComponentUpdate`](/reference/react/Component#shouldcomponentupdate)method that shallowly compares props and state.
45
+
`PureComponent`adalah subkelas dari `Component`dan mendukung [semua API`Component`.](/reference/react/Component#reference)Memperluas`PureComponent`sama dengan mendefinisikan sebuah metode kustom[`shouldComponentUpdate`](/reference/react/Component#shouldcomponentupdate)yang membandingkan props dan state secara dangkal.
46
46
47
47
48
-
[See more examples below.](#usage)
48
+
[Lihat contoh lainnya di bawah ini.](#usage)
49
49
50
50
---
51
51
52
-
## Usage {/*usage*/}
52
+
## Penggunaan {/*usage*/}
53
53
54
-
### Skipping unnecessary re-renders for class components {/*skipping-unnecessary-re-renders-for-class-components*/}
54
+
### Melewatkan *render* ulang yang tidak perlu untuk komponen kelas {/*skipping-unnecessary-re-renders-for-class-components*/}
55
55
56
-
React normally re-renders a component whenever its parent re-renders. As an optimization, you can create a component that React will not re-render when its parent re-renders so long as its new props and state are the same as the old props and state. [Class components](/reference/react/Component)can opt into this behavior by extending`PureComponent`:
56
+
React umumnya me-*render* ulang sebuah komponen setiap kali induknya me-*render* ulang. Untuk mengoptimalkannya, Anda dapat membuat komponen yang tidak akan di-*render* ulang oleh React ketika induknya di-*render* ulang selama props dan state yang baru sama dengan props dan state yang lama. [Komponen kelas](/reference/react/Component)dapat memilih perilaku ini dengan memperluas`PureComponent`:
57
57
58
58
```js {1}
59
59
classGreetingextendsPureComponent {
@@ -63,9 +63,9 @@ class Greeting extends PureComponent {
63
63
}
64
64
```
65
65
66
-
A React component should always have [pure rendering logic.](/learn/keeping-components-pure)This means that it must return the same output if its props, state, and context haven't changed. By using`PureComponent`, you are telling React that your component complies with this requirement, so React doesn't need to re-render as long as its props and state haven't changed. However, your component will still re-render if a context that it's using changes.
66
+
Sebuah komponen React harus selalu memiliki [logika me-*render* murni.](/learn/keeping-components-pure)Ini berarti komponen tersebut harus mengembalikan output yang sama jika props, state, dan konteksnya tidak berubah. Dengan menggunakan`PureComponent`, Anda memberi tahu React bahwa komponen Anda memenuhi persyaratan ini, sehingga React tidak perlu me-*render* ulang selama props dan state-nya belum berubah. Namun, komponen Anda akan tetap di-*render* ulang jika konteks yang digunakan berubah.
67
67
68
-
In this example, notice that the`Greeting`component re-renders whenever `name`is changed (because that's one of its props), but not when`address`is changed (because it's not passed to `Greeting`as a prop):
68
+
Pada contoh ini, perhatikan bahwa komponen`Greeting`di-*render* ulang setiap kali `name`diubah (karena itu adalah salah satu props-nya), tetapi tidak ketika`address`diubah (karena tidak dioper ke `Greeting`sebagai props):
69
69
70
70
<Sandpack>
71
71
@@ -109,17 +109,17 @@ label {
109
109
110
110
<Pitfall>
111
111
112
-
We recommend defining components as functions instead of classes. [See how to migrate.](#alternatives)
112
+
Kami menyarankan untuk membuat komponen sebagai fungsi, bukan kelas. [Lihat cara migrasinya.](#alternatives)
113
113
114
114
</Pitfall>
115
115
116
116
---
117
117
118
-
## Alternatives {/*alternatives*/}
118
+
## Alternatif {/*alternatives*/}
119
119
120
-
### Migrating from a `PureComponent`class component to a function {/*migrating-from-a-purecomponent-class-component-to-a-function*/}
120
+
### Migrasi dari komponen kelas `PureComponent`ke sebuah fungsi {/*migrating-from-a-purecomponent-class-component-to-a-function*/}
121
121
122
-
We recommend using function components instead of [class components](/reference/react/Component)in new code. If you have some existing class components using `PureComponent`, here is how you can convert them. This is the original code:
122
+
Kami menyarankan untuk menggunakan komponen fungsi daripada [komponen kelas](/reference/react/Component)dalam kode baru. Jika Anda memiliki beberapa komponen kelas yang sudah ada menggunakan `PureComponent`, berikut ini cara mengonversinya. Ini adalah kode aslinya:
123
123
124
124
<Sandpack>
125
125
@@ -161,7 +161,7 @@ label {
161
161
162
162
</Sandpack>
163
163
164
-
When you [convert this component from a class to a function,](/reference/react/Component#alternatives)wrap it in [`memo`:](/reference/react/memo)
164
+
Saat Anda [mengonversi komponen ini dari kelas ke fungsi,](/reference/react/Component#alternatives)bungkus komponen ini dengan [`memo`](/reference/react/memo):
165
165
166
166
<Sandpack>
167
167
@@ -203,6 +203,6 @@ label {
203
203
204
204
<Note>
205
205
206
-
Unlike `PureComponent`, [`memo`](/reference/react/memo)does not compare the new and the old state. In function components, calling the [`set` function](/reference/react/useState#setstate)with the same state [already prevents re-renders by default,](/reference/react/memo#updating-a-memoized-component-using-state)even without`memo`.
206
+
Tidak seperti `PureComponent`, [`memo`](/reference/react/memo)tidak membandingkan state yang baru dan state yang lama. Pada komponen fungsi, memanggil [fungsi `set`](/reference/react/useState#setstate)dengan state yang sama [sudah mencegah *render* ulang secara default,](/reference/react/memo#updating-a-memoized-component-using-state)bahkan tanpa`memo`.
0 commit comments