Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: translate API Reference / react / Hooks #367

Merged
merged 28 commits into from
Jun 7, 2023
Merged
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4d2568d
translate react:hooks
KevinPalowa Apr 28, 2023
8b1f656
Merge branch 'main' into docs/translations/react-hooks
KevinPalowa Apr 29, 2023
224b8af
fix: add missing translation
KevinPalowa Apr 29, 2023
488fe55
fix: change word "terpapar" into "terekspos"
KevinPalowa Apr 29, 2023
ed23223
fix: use word "timeout" instead of "batas waktu"
KevinPalowa Apr 29, 2023
9cd2311
fix: typo
KevinPalowa Apr 29, 2023
705fa65
fix: use word "menangguhkan" instead of menunda
KevinPalowa Apr 29, 2023
5436cbe
fix: better wording
KevinPalowa Apr 29, 2023
5532e90
fix: better styling for loadword
KevinPalowa Apr 30, 2023
dc57027
fix: better styling for loadword
KevinPalowa Apr 30, 2023
6af77ac
fix: better styling for loadword
KevinPalowa Apr 30, 2023
3511c8d
fix: better styling for loadword
KevinPalowa Apr 30, 2023
fd20474
fix: better styling for loadword
KevinPalowa Apr 30, 2023
b32b8d4
fix: better styling
KevinPalowa Apr 30, 2023
a660a00
Merge branch 'main' into docs/translations/react-hooks
mhaidarhanif May 1, 2023
49716a2
fix: translate browser & repaint word
KevinPalowa May 1, 2023
da734a2
fix: better translations for repaint
KevinPalowa May 1, 2023
42f8d25
fix: translate non-blockig word
KevinPalowa May 1, 2023
b3275a8
Merge branch 'main' into docs/translations/react-hooks
zainfathoni May 1, 2023
ea59d77
Merge branch 'main' into docs/translations/react-hooks
mhaidarhanif May 1, 2023
588bd4a
fix: Apply suggestions from code review
KevinPalowa May 1, 2023
1e20037
Merge branch 'main' into docs/translations/react-hooks
mhaidarhanif May 1, 2023
821dd23
Merge branch 'main' into docs/translations/react-hooks
KevinPalowa May 5, 2023
9fc07ed
Merge branch 'main' into docs/translations/react-hooks
zainfathoni May 8, 2023
46aa496
fix: add suggestion
KevinPalowa May 9, 2023
398e8e7
Merge branch 'main' into docs/translations/react-hooks
KevinPalowa May 19, 2023
ebd4586
fix: styling & missing period
KevinPalowa May 24, 2023
94f127b
Merge branch 'main' into docs/translations/react-hooks
mazipan Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 37 additions & 40 deletions src/content/reference/react/index.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
---
title: "Built-in React Hooks"
title: "React Hook Bawaan"
---

<Intro>

*Hooks* let you use different React features from your components. You can either use the built-in Hooks or combine them to build your own. This page lists all built-in Hooks in React.
*Hook* memungkinkan Anda menggunakan fitur React dari dalam komponen Anda. Anda dapat menggunakan Hook bawaan atau mengkombinasikan mereka untuk membuat hook Anda sendiri. Halaman ini mencantumkan daftar semua list Hook bawaan yang tersedia di React.

</Intro>

---

## State Hooks {/*state-hooks*/}
## Hook State {/*state-hooks*/}

*State* lets a component ["remember" information like user input.](/learn/state-a-components-memory) For example, a form component can use state to store the input value, while an image gallery component can use state to store the selected image index.
*State* memungkinkan sebuah komponen ["mengingat" informasi seperti masukan pengguna.](/learn/state-a-components-memory) Sebagai contoh, sebuah komponen formulir dapat menggunakan *state* untuk menyimpan nilai masukan, sementara komponen gambar galeri dapat menggunakan state untuk menyimpan indeks gambar yang terpilih.
Untuk menambahkan state ke sebuah komponen, gunakan salah satu Hooks dibawah ini:

To add state to a component, use one of these Hooks:

* [`useState`](/reference/react/useState) declares a state variable that you can update directly.
* [`useReducer`](/reference/react/useReducer) declares a state variable with the update logic inside a [reducer function.](/learn/extracting-state-logic-into-a-reducer)
* [`useState`](/reference/react/useState) mendeklarasi sebuah variabel *state* yang dapat Anda perbarui secara langsung.
* [`useReducer`](/reference/react/useReducer) mendeklarasi sebuah variabel *state* dengan pembaruan logika dalam sebuah [fungsi reducer.](/learn/extracting-state-logic-into-a-reducer)

```js
function ImageGallery() {
Expand All @@ -27,11 +26,10 @@ function ImageGallery() {

---

## Context Hooks {/*context-hooks*/}

*Context* lets a component [receive information from distant parents without passing it as props.](/learn/passing-props-to-a-component) For example, your app's top-level component can pass the current UI theme to all components below, no matter how deep.
## Hook Context {/*context-hooks*/}

* [`useContext`](/reference/react/useContext) reads and subscribes to a context.
*Context* memungkinkan sebuah komponen [menerima informasi dari induk yang jauh tanpa mengopernya sebagai props.](/learn/passing-props-to-a-component) Sebagai contoh, komponen tingkat atas aplikasi Anda dapat meneruskan tema antarmuka pengguna (UI) saat ini ke semua komponen di bawah, tidak peduli seberapa dalam.
* [`useContext`](/reference/react/useContext) membaca dan berlangganan ke sebuah *context*.

```js
function Button() {
Expand All @@ -41,12 +39,11 @@ function Button() {

---

## Ref Hooks {/*ref-hooks*/}

*Refs* let a component [hold some information that isn't used for rendering,](/learn/referencing-values-with-refs) like a DOM node or a timeout ID. Unlike with state, updating a ref does not re-render your component. Refs are an "escape hatch" from the React paradigm. They are useful when you need to work with non-React systems, such as the built-in browser APIs.
## Hook Ref {/*ref-hooks*/}
*Refs* memungkinkan sebuah komponen [menyimpan beberapa informasi yang tidak digunakan untuk dirender](/learn/referencing-values-with-refs) seperti node DOM atau ID *timeout*. Tidak seperti state, memperbarui *ref* tidak merender ulang komponen Anda. Ref adalah jalan keluar dari paradigma React. *Ref* berguna ketika Anda membutuhkan untuk bekerja dengan sistem non-React, seperti *API* browser bawaan.

* [`useRef`](/reference/react/useRef) declares a ref. You can hold any value in it, but most often it's used to hold a DOM node.
* [`useImperativeHandle`](/reference/react/useImperativeHandle) lets you customize the ref exposed by your component. This is rarely used.
* [`useRef`](/reference/react/useRef) mendeklarasi *ref*. Anda dapat menyimpan nilai apapun didalamnya, tapi *ref* sering kali digunakan untuk menyimpan node DOM.
* [`useImperativeHandle`](/reference/react/useImperativeHandle) memungkinkan Anda menyesuaikan *ref* yang terekspos oleh komponen Anda. Ini jarang sekali digunakan.

```js
function Form() {
Expand All @@ -56,11 +53,11 @@ function Form() {

---

## Effect Hooks {/*effect-hooks*/}
## Hook Efek {/*effect-hooks*/}

*Effects* let a component [connect to and synchronize with external systems.](/learn/synchronizing-with-effects) This includes dealing with network, browser DOM, animations, widgets written using a different UI library, and other non-React code.
*Efek* memungkinkan sebuah komponen [terhubung dan menyesuaikan dengan sistem eksternal](/learn/synchronizing-with-effects) Ini termasuk berurusan dengan jaringan, browser DOM, animasi, widget yang ditulis menggunakan UI pustaka lain, dan kode non-React lainnya.

* [`useEffect`](/reference/react/useEffect) connects a component to an external system.
* [`useEffect`](/reference/react/useEffect) menghubungkan sebuah komponen ke sebuah sistem eksternal.

```js
function ChatRoom({ roomId }) {
Expand All @@ -72,23 +69,23 @@ function ChatRoom({ roomId }) {
// ...
```

Effects are an "escape hatch" from the React paradigm. Don't use Effects to orchestrate the data flow of your application. If you're not interacting with an external system, [you might not need an Effect.](/learn/you-might-not-need-an-effect)
Efek adalah jalan keluar dari paradigma React. Jangan gunakan Efek untuk mengatur aliran data aplikasi Anda. Jika Anda tidak berinteraksi dengan sistem eksternal, [Kemungkinan Besar Anda Tidak Memerlukan Efek](/learn/you-might-not-need-an-effect)

There are two rarely used variations of `useEffect` with differences in timing:
Terdapat dua variasi dari `useEffect` yang jarang digunakan dengan perbedaan pada waktu-nya

* [`useLayoutEffect`](/reference/react/useLayoutEffect) fires before the browser repaints the screen. You can measure layout here.
* [`useInsertionEffect`](/reference/react/useInsertionEffect) fires before React makes changes to the DOM. Libraries can insert dynamic CSS here.
* [`useLayoutEffect`](/reference/react/useLayoutEffect) dipanggil sebelum browser melakukan repaint layar. Anda dapat menggunakannya untuk mengukur layout pada tahap ini.
* [`useInsertionEffect`](/reference/react/useInsertionEffect) dipanggil sebelum React melakukan perubahan ke DOM. Pustaka - pustaka dapat memasukkan CSS dinamik disini.

---

## Performance Hooks {/*performance-hooks*/}
## Hook Performa {/*performance-hooks*/}

A common way to optimize re-rendering performance is to skip unnecessary work. For example, you can tell React to reuse a cached calculation or to skip a re-render if the data has not changed since the previous render.
Cara yang umum untuk mengoptimalkan kinerja pen-renderan ulang adalah melewatkan pekerjaan yang tidak perlu. Sebagai contoh, Anda dapat memberi tahu React untuk menggunakan kembali perhitungan yang sudah ada di dalam cache atau untuk melewatkan pen-renderan ulang jika data tersebut tidak berubah sejak render sebelumnya.

To skip calculations and unnecessary re-rendering, use one of these Hooks:
Untuk melewatkan perhitungan dan render ulang yang tidak perlu, gunakan salah satu dari Hook ini:

- [`useMemo`](/reference/react/useMemo) lets you cache the result of an expensive calculation.
- [`useCallback`](/reference/react/useCallback) lets you cache a function definition before passing it down to an optimized component.
- [`useMemo`](/reference/react/useMemo) memungkinkan Anda menyimpan hasil perhitungan yang berat secara cache.
- [`useCallback`](/reference/react/useCallback) memungkinkan Anda menyimpan definisi fungsi di cache sebelum melewatkannya ke komponen yang dioptimalkan.

```js
function TodoList({ todos, tab, theme }) {
Expand All @@ -97,25 +94,25 @@ function TodoList({ todos, tab, theme }) {
}
```

Sometimes, you can't skip re-rendering because the screen actually needs to update. In that case, you can improve performance by separating blocking updates that must be synchronous (like typing into an input) from non-blocking updates which don't need to block the user interface (like updating a chart).
Terkadang, Anda tidak dapat melewatkan pe-*render*an ulang karena layar sebenarnya perlu pembaruan. Di dalam kasus itu, Anda dapat meningkatkan performa dengan memisahkan memblokir pembaruan yang harus sinkron (seperti mengetik masukan) dari pembaruan non-pemblokiran yang tidak perlu memblokir antarmuka pengguna (seperti memperbarui bagan).

To prioritize rendering, use one of these Hooks:
Untuk memprioritaskan rendering, gunakan salah satu Hook ini:

- [`useTransition`](/reference/react/useTransition) lets you mark a state transition as non-blocking and allow other updates to interrupt it.
- [`useDeferredValue`](/reference/react/useDeferredValue) lets you defer updating a non-critical part of the UI and let other parts update first.
- [`useTransition`](/reference/react/useTransition) memungkinkan Anda menandai transisi state sebagai non-blocking dan mengizinkan pembaruan lain untuk menghentikannya.
- [`useDeferredValue`](/reference/react/useDeferredValue) memungkinkan Anda menangguhkan pembaruan bagian antarmuka pengguna (UI) yang tidak penting dan membiarkan bagian lain memperbarui terlebih dahulu.

---

## Other Hooks {/*other-hooks*/}
## Hook lainnya {/*other-hooks*/}

These Hooks are mostly useful to library authors and aren't commonly used in the application code.
Ini adalah Hook yang sebagian besar berguna untuk penulis pustaka dan tidak umum digunakan di dalam kode aplikasi.

- [`useDebugValue`](/reference/react/useDebugValue) lets you customize the label React DevTools displays for your custom Hook.
- [`useId`](/reference/react/useId) lets a component associate a unique ID with itself. Typically used with accessibility APIs.
- [`useSyncExternalStore`](/reference/react/useSyncExternalStore) lets a component subscribe to an external store.
- [`useDebugValue`](/reference/react/useDebugValue) memungkinkan Anda memodifikasi tampilan label React DevTools untuk Hook kustom Anda.
- [`useId`](/reference/react/useId) memungkinkan komponen mengasosiasikan ID unik dengan dirinya sendiri. Biasanya digunakan dengan API aksesibilitas.
- [`useSyncExternalStore`](/reference/react/useSyncExternalStore) memungkinkan komponen berlangganan ke *store* eksternal.

---

## Your own Hooks {/*your-own-hooks*/}
## Hook Anda sendiri {/*your-own-hooks*/}

You can also [define your own custom Hooks](/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component) as JavaScript functions.
Anda juga dapat [mendefinisikan Hook kustom Anda sendiri](/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component) sebagai fungsi JavaScript.