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/learn/keeping-components-pure.md
+18-18Lines changed: 18 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -16,36 +16,36 @@ Beberapa fungsi JavaScript bersifat murni, yaitu hanya melakukan kalkulasi. Deng
16
16
17
17
</YouWillLearn>
18
18
19
-
## Purity: Components as formulas {/*purity-components-as-formulas*/}
19
+
## Kemurnian: Komponen sebagai rumus {/*purity-components-as-formulas*/}
20
20
21
-
In computer science (and especially the world of functional programming), [a pure function](https://wikipedia.org/wiki/Pure_function)is a function with the following characteristics:
21
+
Dalam ilmu komputer, terutama di dunia pemrograman fungsional, [fungsi murni](https://wikipedia.org/wiki/Pure_function)adalah sebuah fungsi yang memenuhi kriteria berikut:
22
22
23
-
***It minds its own business.**It does not change any objects or variables that existed before it was called.
24
-
***Same inputs, same output.**Given the same inputs, a pure function should always return the same result.
23
+
***Dia hanya mengurus dirinya sendiri.**Dia tidak mengubah objek atau variabel yang ada sebelum dia dipanggil.
24
+
***Masukan yang sama, luaran yang sama.**Untuk masukan yang sama, fungsi murni akan selalu menghasilkan luaran yang sama.
25
25
26
-
You might already be familiar with one example of pure functions: formulas in math.
26
+
Anda mungkin sudah akrab dengan salah satu contoh fungsi murni, yaitu rumus-rumus dalam matematika.
27
27
28
-
Consider this math formula: <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math>.
If <Math><MathI>x</MathI> = 2</Math> then <Math><MathI>y</MathI> = 4</Math>. Always.
30
+
Jika <Math><MathI>x</MathI> = 2</Math>, <Math><MathI>y</MathI> = 4</Math>. Selalu.
31
31
32
-
If <Math><MathI>x</MathI> = 3</Math> then <Math><MathI>y</MathI> = 6</Math>. Always.
32
+
Jika <Math><MathI>x</MathI> = 3</Math>, <Math><MathI>y</MathI> = 6</Math>. Selalu.
33
33
34
-
If <Math><MathI>x</MathI> = 3</Math>, <MathI>y</MathI> won't sometimes be <Math>9</Math> or <Math>–1</Math> or <Math>2.5</Math> depending on the time of day or the state of the stock market.
34
+
Jika <Math><MathI>x</MathI> = 3</Math>, <MathI>y</MathI> tidak mungkin bernilai <Math>9</Math> ataupun <Math>–1</Math> ataupun <Math>2.5</Math> hanya karena ada pergantian hari atau pergerakan bursa saham.
35
35
36
-
If <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> and <Math><MathI>x</MathI> = 3</Math>, <MathI>y</MathI> will _always_ be <Math>6</Math>.
36
+
Jika <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> dan <Math><MathI>x</MathI> = 3</Math>, <MathI>y</MathI> akan *selalu* bernilai <Math>6</Math>.
37
37
38
-
If we made this into a JavaScript function, it would look like this:
38
+
Jika kita mengonversi rumus ini menjadi fungsi JavaScript, fungsi tersebut akan terlihat seperti ini:
39
39
40
40
```js
41
41
functiondouble(number) {
42
42
return2* number;
43
43
}
44
44
```
45
45
46
-
In the above example, `double`is a**pure function.** If you pass it `3`, it will return `6`. Always.
46
+
Pada contoh di atas, `double`adalah sebuah**fungsi murni**. Jika Anda masukkan `3`, fungsi itu akan mengembalikan `6`. Selalu.
47
47
48
-
React is designed around this concept. **React assumes that every component you write is a pure function.** This means that React components you write must always return the same JSX given the same inputs:
48
+
React dibuat berdasarkan konsep ini. **React berasumsi kalau setiap komponen yang Anda buat adalah fungsi murni**. Ini berarti komponen React yang Anda buat harus selalu menghasilkan JSX yang sama jika diberikan masukan yang sama:
49
49
50
50
<Sandpack>
51
51
@@ -75,15 +75,15 @@ export default function App() {
75
75
76
76
</Sandpack>
77
77
78
-
When you pass`drinkers={2}`to`Recipe`, it will return JSX containing `2 cups of water`. Always.
78
+
Jika Anda memberikan`drinkers={2}`ke`Recipe`, komponen tersebut akan mengembalikan JSX yang berisi `2 cups of water`. Selalu.
79
79
80
-
If you pass`drinkers={4}`, it will return JSX containing `4 cups of water`. Always.
80
+
Jika Anda memberikan`drinkers={4}`, komponen tersebut akan mengembalikan JSX yang berisi `4 cups of water`. Selalu.
81
81
82
-
Just like a math formula.
82
+
Seperti rumus matematika.
83
83
84
-
You could think of your components as recipes: if you follow them and don't introduce new ingredients during the cooking process, you will get the same dish every time. That "dish" is the JSX that the component serves to React to [render.](/learn/render-and-commit)
84
+
Anda bisa menganggap komponen Anda sebagai resep: jika Anda mengikuti resep tersebut dan tidak menambahkan bahan apapun dalam proses pemasakan, Anda akan selalu mendapatkan makanan yang sama. "Makanan" itu adalah JSX yang diserahkan sebuah komponen ke React untuk di-[*render*](/learn/render-and-commit).
85
85
86
-
<Illustrationsrc="/images/docs/illustrations/i_puritea-recipe.png"alt="A tea recipe for x people: take x cups of water, add x spoons of tea and 0.5x spoons of spices, and 0.5x cups of milk" />
86
+
<Illustrationsrc="/images/docs/illustrations/i_puritea-recipe.png"alt="Sebuah resep teh untuk x orang: membutuhkan x gelas air, tambahkan teh sebanyak x sendok, tambahkan rempah sebanyak 0,5 sendok, dan 0,5 gelas susu" />
87
87
88
88
## Side Effects: (un)intended consequences {/*side-effects-unintended-consequences*/}
0 commit comments