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: content/docs/fragments.md
+20-17Lines changed: 20 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@ title: Fragments
4
4
permalink: docs/fragments.html
5
5
---
6
6
7
-
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.
7
+
Pola umum dalam React adalah agar komponen mengembalikan banyak elemen. Fragmen memungkinkan anda mengelompokkan daftar komponen-komponen tanpa menambahkan node tambahan ke DOM.
8
+
8
9
9
10
```js
10
11
render() {
@@ -18,11 +19,12 @@ render() {
18
19
}
19
20
```
20
21
21
-
There is also a new [short syntax](#short-syntax) for declaring them.
22
+
Ada juga [sintaks pendek](#short-syntax) untuk mendeklarasikannya.
23
+
24
+
## Motivasi {#motivation}
22
25
23
-
## Motivation {#motivation}
26
+
Pola umum pada komponen adalah mengembalikan daftar komponen-komponen. Ambil potongan contoh react ini:
24
27
25
-
A common pattern is for a component to return a list of children. Take this example React snippet:
26
28
27
29
```jsx
28
30
classTableextendsReact.Component {
@@ -38,7 +40,7 @@ class Table extends React.Component {
38
40
}
39
41
```
40
42
41
-
`<Columns />`would need to return multiple `<td>`elements in order for the rendered HTML to be valid. If a parent div was used inside the`render()`of`<Columns />`, then the resulting HTML will be invalid.
43
+
`<Columns />`perlu mengembalikan beberapa `<td>`elemen agar HTML yang diberikan menjadi benar. Jika div induk digunakan di dalam`render()`dari`<Columns />`, maka HTML yang dihasilkan tidak benar.
42
44
43
45
```jsx
44
46
classColumnsextendsReact.Component {
@@ -53,7 +55,7 @@ class Columns extends React.Component {
53
55
}
54
56
```
55
57
56
-
results in a `<Table />`output of:
58
+
menghasilkan keluaran `<Table />`dari:
57
59
58
60
```jsx
59
61
<table>
@@ -66,9 +68,9 @@ results in a `<Table />` output of:
66
68
</table>
67
69
```
68
70
69
-
Fragments solve this problem.
71
+
Fragmen memecahkan masalah ini
70
72
71
-
## Usage {#usage}
73
+
## Penggunaan {#usage}
72
74
73
75
```jsx{4,7}
74
76
class Columns extends React.Component {
@@ -83,7 +85,7 @@ class Columns extends React.Component {
83
85
}
84
86
```
85
87
86
-
which results in a correct `<Table />`output of:
88
+
yang menghasilkan keluaran `<Table />`yang benar:
87
89
88
90
```jsx
89
91
<table>
@@ -94,9 +96,9 @@ which results in a correct `<Table />` output of:
94
96
</table>
95
97
```
96
98
97
-
### Short Syntax {#short-syntax}
99
+
### Sintaks Pendek {#short-syntax}
98
100
99
-
There is a new, shorter syntax you can use for declaring fragments. It looks like empty tags:
101
+
Ada yang baru, sintaks yang lebih pendek dapat anda gunakan untuk mendeklarasikan fragmen. seperti tag kosong:
100
102
101
103
```jsx{4,7}
102
104
class Columns extends React.Component {
@@ -111,18 +113,18 @@ class Columns extends React.Component {
111
113
}
112
114
```
113
115
114
-
You can use`<></>`the same way you'd use any other element except that it doesn't support keys or attributes.
116
+
Anda dapat menggunakan`<></>`dengan cara yang sama anda akan menggunakan elemen lain kecuali itu tidak medukung *key* atau atribut.
115
117
116
118
### Keyed Fragments {#keyed-fragments}
117
119
118
-
Fragments declared with the explicit `<React.Fragment>`syntax may have keys. A use case for this is mapping a collection to an array of fragments -- for example, to create a description list:
120
+
Fragmen dideklarasikan dengan eksplisit `<React.Fragment>`sintaks mungkin memiliki *key*. Kasus penggunaan untuk ini adalah memetakan koleksi ke array fragmen -- untuk contoh, untuk membuat daftar deskripsi:
119
121
120
122
```jsx
121
123
functionGlossary(props) {
122
124
return (
123
125
<dl>
124
126
{props.items.map(item=> (
125
-
//Without the `key`, React will fire a key warning
127
+
//Tanpa sebuah `key`, React akan mengeluarkan peringatan
126
128
<React.Fragment key={item.id}>
127
129
<dt>{item.term}</dt>
128
130
<dd>{item.description}</dd>
@@ -133,8 +135,9 @@ function Glossary(props) {
133
135
}
134
136
```
135
137
136
-
`key` is the only attribute that can be passed to `Fragment`. In the future, we may add support for additional attributes, such as event handlers.
138
+
`key` adalah satu-satunya atribut yang dapat dteruskan ke `Fragment`. Dimasa mendatang, kami dapat menambahkan dukungan untuk atribut tambahan, seperti *event handlers*.
139
+
140
+
### Demo langsung {#live-demo}
137
141
138
-
### Live Demo {#live-demo}
142
+
Anda dapat mencoba sintaks JSX fragmen baru dengan ini [CodePen](https://codepen.io/reactjs/pen/VrEbjE?editors=1000).
139
143
140
-
You can try out the new JSX fragment syntax with this [CodePen](https://codepen.io/reactjs/pen/VrEbjE?editors=1000).
0 commit comments