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/updating-arrays-in-state.md
+40-40Lines changed: 40 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -777,21 +777,21 @@ Di belakang layar, Immer selalu membuat state berikutnya dari awal sesuai dengan
777
777
778
778
<Recap>
779
779
780
-
-You can put arrays into state, but you can't change them.
781
-
-Instead of mutating an array, create a *new* version of it, and update the state to it.
782
-
-You can use the `[...arr, newItem]`array spread syntax to create arrays with new items.
783
-
-You can use`filter()`and`map()`to create new arrays with filtered or transformed items.
784
-
-You can use Immer to keep your code concise.
780
+
-Anda dapat memasukkan senarai ke dalam state, tetapi Anda tidak dapat mengubahnya.
781
+
-Alih-alih memutasi senarai, buat versi *barunya*, dan perbarui state tersebut.
782
+
-Anda dapat menggunakan penyebaran sintaksis senarai `[...arr, newItem]`untuk membuat senarai dengan item baru.
783
+
-Anda dapat menggunakan`filter()`dan`map()`untuk membuat senarai baru dengan item yang difilter atau diubah.
784
+
-Anda dapat menggunakan Immer untuk menjaga agar kode Anda tetap ringkas.
785
785
786
786
</Recap>
787
787
788
788
789
789
790
790
<Challenges>
791
791
792
-
#### Update an item in the shopping cart {/*update-an-item-in-the-shopping-cart*/}
792
+
#### Memperbarui item di keranjang belanja {/*update-an-item-in-the-shopping-cart*/}
793
793
794
-
Fill in the `handleIncreaseClick`logic so that pressing "+" increases the corresponding number:
794
+
Isi logika `handleIncreaseClick`sehingga saat menekan "+" akan meningkatkan angka yang sesuai:
795
795
796
796
<Sandpack>
797
797
@@ -849,7 +849,7 @@ button { margin: 5px; }
849
849
850
850
<Solution>
851
851
852
-
You can use the`map`function to create a new array, and then use the `...`object spread syntax to create a copy of the changed object for the new array:
852
+
Anda dapat menggunakan fungsi`map`untuk membuat senarai baru, lalu menggunakan penyebaran sintaksis objek `...`untuk membuat salinan objek yang diubah untuk senarai baru:
853
853
854
854
<Sandpack>
855
855
@@ -916,9 +916,9 @@ button { margin: 5px; }
916
916
917
917
</Solution>
918
918
919
-
#### Remove an item from the shopping cart {/*remove-an-item-from-the-shopping-cart*/}
919
+
#### Menghapus item dari keranjang belanja {/*remove-an-item-from-the-shopping-cart*/}
920
920
921
-
This shopping cart has a working "+" button, but the "–" button doesn't do anything. You need to add an event handler to it so that pressing it decreases the `count`of the corresponding product. If you press "–" when the count is 1, the product should automatically get removed from the cart. Make sure it never shows 0.
921
+
Keranjang belanja ini memiliki tombol "+" yang berfungsi, tetapi tombol "–" tidak melakukan apa-apa. Anda perlu menambahkan *event handler* ke dalamnya sehingga saat menekannya akan mengurangi `count`produk yang sesuai. Jika Anda menekan "–" saat `count`1, produk akan secara otomatis dihapus dari keranjang. Pastikan itu tidak pernah menunjukkan 0.
922
922
923
923
<Sandpack>
924
924
@@ -988,7 +988,7 @@ button { margin: 5px; }
988
988
989
989
<Solution>
990
990
991
-
You can first use`map`to produce a new array, and then `filter`to remove products with a `count`set to `0`:
991
+
Pertama-tama Anda dapat menggunakan`map`untuk menghasilkan senarai baru, lalu `filter`untuk menghapus produk dengan `count`yang disetel ke 0:
992
992
993
993
<Sandpack>
994
994
@@ -1077,9 +1077,9 @@ button { margin: 5px; }
1077
1077
1078
1078
</Solution>
1079
1079
1080
-
#### Fix the mutations using non-mutative methods {/*fix-the-mutations-using-non-mutative-methods*/}
1080
+
#### Perbaiki mutasi menggunakan metode nonmutatif {/*fix-the-mutations-using-non-mutative-methods*/}
1081
1081
1082
-
In this example, all of the event handlers in `App.js` use mutation. As a result, editing and deleting todos doesn't work. Rewrite `handleAddTodo`, `handleChangeTodo`, and`handleDeleteTodo`to use the non-mutative methods:
1082
+
Pada contoh ini, semua *event handler* di App.js menggunakan mutasi. Akibatnya, mengedit dan menghapus todos tidak berfungsi. Tulis ulang `handleAddTodo`, `handleChangeTodo`, dan`handleDeleteTodo`untuk menggunakan metode *non-mutatif*:
In`handleAddTodo`, you can use the array spread syntax. In`handleChangeTodo`, you can create a new array with `map`. In`handleDeleteTodo`, you can create a new array with `filter`. Now the list works correctly:
1245
+
Pada`handleAddTodo`, Anda bisa menggunakan sintaksis penyebaran senarai. Pada`handleChangeTodo`, Anda dapat membuat senarai baru dengan `map`. Pada`handleDeleteTodo`, Anda dapat membuat senarai baru dengan `filter`. Sekarang daftar berfungsi dengan benar:
#### Fix the mutations using Immer {/*fix-the-mutations-using-immer*/}
1413
+
#### Perbaiki mutasi menggunakan Immer {/*fix-the-mutations-using-immer*/}
1414
1414
1415
-
This is the same example as in the previous challenge. This time, fix the mutations by using Immer. For your convenience, `useImmer`is already imported, so you need to change the`todos`state variable to use it.
1415
+
Ini adalah contoh yang sama seperti pada tantangan sebelumnya. Kali ini, perbaiki mutasi dengan menggunakan Immer. Untuk kemudahan Anda, `useImmer`sudah diimpor, jadi Anda perlu mengubah variabel state`todos`untuk menggunakannya.
With Immer, you can write code in the mutative fashion, as long as you're only mutating parts of the `draft`that Immer gives you. Here, all mutations are performed on the `draft` so the code works:
1597
+
Dengan Immer, Anda dapat menulis kode dengan gaya yang dapat bermutasi, selama Anda hanya memutasi bagian-bagian dari `draft`yang diberikan oleh Immer. Di sini, semua mutasi dilakukan pada `draft`, jadi kode berfungsi:
You can also mix and match the mutative and non-mutative approaches with Immer.
1783
+
Anda juga dapat mencampur dan mencocokkan pendekatan *mutatif* dan *non-mutatif* dengan Immer.
1784
1784
1785
-
For example, in this version`handleAddTodo`is implemented by mutating the Immer `draft`, while`handleChangeTodo`and`handleDeleteTodo`use the non-mutative `map`and`filter`methods:
1785
+
Misalnya, dalam versi ini`handleAddTodo`diimplementasikan dengan mengubah `draft` Immer, sedangkan`handleChangeTodo`dan`handleDeleteTodo`menggunakan metode `map`dan`filter`*non-mutatif*:
0 commit comments