Skip to content

Commit 2968e4f

Browse files
committed
refactor(reusing-logic-with-custom-hooks.md): translate the article to Indonesian
1 parent c8e1c31 commit 2968e4f

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/content/learn/reusing-logic-with-custom-hooks.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
---
2-
title: 'Reusing Logic with Custom Hooks'
2+
title: 'Menggunakan ulang logika dengan Custom Hooks'
33
---
44

55
<Intro>
66

7-
React comes with several built-in Hooks like `useState`, `useContext`, and `useEffect`. Sometimes, you'll wish that there was a Hook for some more specific purpose: for example, to fetch data, to keep track of whether the user is online, or to connect to a chat room. You might not find these Hooks in React, but you can create your own Hooks for your application's needs.
7+
React dilengkapi dengan beberapa Hook bawaan seperti `useState`, `useContext`, dan `useEffect`. Terkadang, Anda mungkin ingin ada Hook untuk tujuan yang lebih spesifik: misalnya, untuk mengambil data, melacak apakah pengguna sedang online, atau terhubung ke ruang obrolan. Anda mungkin tidak menemukan Hook ini di React, tetapi Anda dapat membuat Hook Anda sendiri untuk kebutuhan aplikasi Anda.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
- What custom Hooks are, and how to write your own
14-
- How to reuse logic between components
15-
- How to name and structure your custom Hooks
16-
- When and why to extract custom Hooks
13+
- Apa itu custom Hooks, dan bagaimana menulis Hooks sendiri
14+
- Bagaimana cara menggunakan ulang logika antara komponen
15+
- Bagaimana memberi nama dan mengatur struktur Hooks yang dibuat sendiri
16+
- Kapan dan mengapa harus mengekstrak custom Hooks
1717

1818
</YouWillLearn>
1919

20-
## Custom Hooks: Sharing logic between components {/*custom-hooks-sharing-logic-between-components*/}
20+
## Custom Hooks: Berbagi logika antar komponen {/*custom-hooks-sharing-logic-between-components*/}
2121

22-
Imagine you're developing an app that heavily relies on the network (as most apps do). You want to warn the user if their network connection has accidentally gone off while they were using your app. How would you go about it? It seems like you'll need two things in your component:
22+
Bayangkan Anda sedang mengembangkan aplikasi yang sangat bergantung pada jaringan (seperti kebanyakan aplikasi). Anda ingin memberi peringatan kepada pengguna jika koneksi jaringannya tiba-tiba terputus saat mereka menggunakan aplikasi Anda. Bagaimana cara melakukannya? Sepertinya Anda akan memerlukan dua hal dalam komponen Anda:
2323

24-
1. A piece of state that tracks whether the network is online.
25-
2. An Effect that subscribes to the global [`online`](https://developer.mozilla.org/en-US/docs/Web/API/Window/online_event) and [`offline`](https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event) events, and updates that state.
24+
1. Sebuah keadaan (state) yang melacak apakah jaringan online.
25+
2. Sebuah Efek yang berlangganan (subscribes) pada peristiwa (events) [`online`](https://developer.mozilla.org/en-US/docs/Web/API/Window/online_event) dan [`offline`](https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event) global, dan memperbarui state tersebut.
2626

27-
This will keep your component [synchronized](/learn/synchronizing-with-effects) with the network status. You might start with something like this:
27+
Hal ini akan menjaga [sinkronisasi](/learn/synchronizing-with-effects) komponen Anda dengan status jaringan. Anda mungkin memulainya dengan sesuatu seperti ini:
2828

2929
<Sandpack>
3030

@@ -54,11 +54,11 @@ export default function StatusBar() {
5454

5555
</Sandpack>
5656

57-
Try turning your network on and off, and notice how this `StatusBar` updates in response to your actions.
57+
Coba matikan dan nyalakan jaringan Anda, dan perhatikan bagaimana `StatusBar` ini diperbarui sebagai respons terhadap tindakan Anda.
5858

59-
Now imagine you *also* want to use the same logic in a different component. You want to implement a Save button that will become disabled and show "Reconnecting..." instead of "Save" while the network is off.
59+
Sekarang bayangkan Anda *juga* ingin menggunakan logika yang sama pada komponen yang berbeda. Anda ingin mengimplementasikan tombol Simpan yang akan menjadi tidak aktif dan menunjukkan "Sedang menghubungkan kembali..." alih-alih "Simpan" saat jaringan mati.
6060

61-
To start, you can copy and paste the `isOnline` state and the Effect into `SaveButton`:
61+
Untuk memulai, Anda dapat menyalin dan mem-paste state `isOnline` dan Efeknya ke dalam `SaveButton`:
6262

6363
<Sandpack>
6464

@@ -96,13 +96,13 @@ export default function SaveButton() {
9696

9797
</Sandpack>
9898

99-
Verify that, if you turn off the network, the button will change its appearance.
99+
Pastikan, jika Anda mematikan jaringan, tampilan tombol tersebut akan berubah.
100100

101-
These two components work fine, but the duplication in logic between them is unfortunate. It seems like even though they have different *visual appearance,* you want to reuse the logic between them.
101+
Kedua komponen ini berfungsi dengan baik, tetapi duplikasi logika di antara keduanya tidak diinginkan. Meskipun mereka memiliki *tampilan visual* yang berbeda, Anda ingin menggunakan kembali logika yang sama di antara keduanya.
102102

103-
### Extracting your own custom Hook from a component {/*extracting-your-own-custom-hook-from-a-component*/}
103+
### Mengekstrak custom Hook Anda sendiri dari sebuah komponen {/*extracting-your-own-custom-hook-from-a-component*/}
104104

105-
Imagine for a moment that, similar to [`useState`](/reference/react/useState) and [`useEffect`](/reference/react/useEffect), there was a built-in `useOnlineStatus` Hook. Then both of these components could be simplified and you could remove the duplication between them:
105+
Bayangkan bahwa, serupa dengan [`useState`](/reference/react/useState) dan [`useEffect`](/reference/react/useEffect), ada sebuah Hook `useOnlineStatus` bawaan. Kemudian kedua komponen ini bisa disederhanakan dan Anda dapat menghapus duplikasi di antara keduanya:
106106

107107
```js {2,7}
108108
function StatusBar() {
@@ -124,8 +124,7 @@ function SaveButton() {
124124
);
125125
}
126126
```
127-
128-
Although there is no such built-in Hook, you can write it yourself. Declare a function called `useOnlineStatus` and move all the duplicated code into it from the components you wrote earlier:
127+
Meskipun tidak ada Hook bawaan seperti itu, Anda dapat menulisnya sendiri. Deklarasikan fungsi bernama `useOnlineStatus` dan pindahkan semua kode duplikat ke dalamnya dari komponen yang Anda tulis sebelumnya:
129128

130129
```js {2-16}
131130
function useOnlineStatus() {

0 commit comments

Comments
 (0)