From c9aedc35aa6b98f45906560c26516db5ad93b0c5 Mon Sep 17 00:00:00 2001 From: rianonehub Date: Wed, 13 Feb 2019 00:48:39 +0700 Subject: [PATCH 01/10] Translate Test Renderer --- content/docs/reference-test-renderer.md | 67 +++++++++++++------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/content/docs/reference-test-renderer.md b/content/docs/reference-test-renderer.md index 473dfb7ec..b6724eab3 100644 --- a/content/docs/reference-test-renderer.md +++ b/content/docs/reference-test-renderer.md @@ -1,25 +1,26 @@ --- id: test-renderer -title: Test Renderer +title: Uji Renderer permalink: docs/test-renderer.html layout: docs category: Reference --- -**Importing** +**Pengimporan** ```javascript import TestRenderer from 'react-test-renderer'; // ES6 -const TestRenderer = require('react-test-renderer'); // ES5 with npm +const TestRenderer = require('react-test-renderer'); // ES5 dengan npm ``` -## Overview {#overview} +## Ikhtisar {#overview} -This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment. -Essentially, this package makes it easy to grab a snapshot of the platform view hierarchy (similar to a DOM tree) rendered by a React DOM or React Native component without using a browser or [jsdom](https://github.com/tmpvar/jsdom). +*Package* ini menyediakan *renderer* React yang dapat digunakan untuk me-*render* komponen React menjadi objek JavaScript murni, tanpa bergantung pada DOM atau bahasa *native* pada telepon seluler. -Example: +Pada dasarnya, *package* ini membuat kemudahan untuk mengambil potret awal dari hierarki tampilan *platform* (mirip dengan pohon DOM) yang di-*render* oleh React DOM atau komponen React Native tanpa menggunakan *browser* atau [jsdom](https://github.com/tmpvar/jsdom). + +Contoh: ```javascript import TestRenderer from 'react-test-renderer'; @@ -38,9 +39,9 @@ console.log(testRenderer.toJSON()); // children: [ 'Facebook' ] } ``` -You can use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: [Learn more about it](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html). +Anda dapat menggunakan fitur pengujian potret awal dari Jest untuk menyimpan salinan pohon JSON ke *file* secara otomatis dan memeriksa bahwa pengujian Anda tidak berubah: [Pelajari lebih lanjut](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html). -You can also traverse the output to find specific nodes and make assertions about them. +Anda juga dapat melewati ke bagian keluaran untuk menemukan *node* tertentu dan membuat pernyataan tentang *node - node* tersebut. ```javascript import TestRenderer from 'react-test-renderer'; @@ -94,7 +95,7 @@ expect(testInstance.findByProps({className: "sub"}).children).toEqual(['Sub']); * [`testInstance.parent`](#testinstanceparent) * [`testInstance.children`](#testinstancechildren) -## Reference {#reference} +## Referensi {#reference} ### `TestRenderer.create()` {#testrenderercreate} @@ -102,7 +103,7 @@ expect(testInstance.findByProps({className: "sub"}).children).toEqual(['Sub']); TestRenderer.create(element, options); ``` -Create a `TestRenderer` instance with the passed React element. It doesn't use the real DOM, but it still fully renders the component tree into memory so you can make assertions about it. The returned instance has the following methods and properties. +Membuat *instance* `TestRenderer` dengan mengoper elemen React. Hal ini tidak menggunakan DOM asli, tetapi masih sepenuhnya me-*render* pohon komponen ke dalam memori sehingga Anda dapat membuat sebuah pernyataan. *Instance* yang dihasilkan memiliki *method* dan *property* sebagai berikut. ### `testRenderer.toJSON()` {#testrenderertojson} @@ -110,7 +111,7 @@ Create a `TestRenderer` instance with the passed React element. It doesn't use t testRenderer.toJSON() ``` -Return an object representing the rendered tree. This tree only contains the platform-specific nodes like `
` or `` and their props, but doesn't contain any user-written components. This is handy for [snapshot testing](http://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest). +Menghasilkan objek yang merepresentasikan pohon yang telah di-*render*. Pohon ini hanya berisi *node* *platform* khusus seperti `
` atau `` dan beserta *props*-nya, tetapi tidak mengandung komponen yang dibuat oleh pengguna. Hal ini berguna untuk [pengujian potret](http://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest). ### `testRenderer.toTree()` {#testrenderertotree} @@ -118,7 +119,7 @@ Return an object representing the rendered tree. This tree only contains the pla testRenderer.toTree() ``` -Return an object representing the rendered tree. Unlike `toJSON()`, the representation is more detailed than the one provided by `toJSON()`, and includes the user-written components. You probably don't need this method unless you're writing your own assertion library on top of the test renderer. +Menghasilkan objek yang merepresentasikan pohon yang telah di-*render*. Tidak seperti `toJSON ()`, representasinya lebih detail daripada yang dihasilkan oleh `toJSON ()`, dan termasuk komponen yang dibuat pengguna. Anda mungkin tidak memerlukan *method* ini kecuali Anda sedang membuat *library* pernyataan sendiri di atas uji *renderer*. ### `testRenderer.update()` {#testrendererupdate} @@ -126,7 +127,7 @@ Return an object representing the rendered tree. Unlike `toJSON()`, the represen testRenderer.update(element) ``` -Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree. +Me-*render* ulang pohon dalam memori dengan elemen *root* baru. Hal Ini mensimulasikan pembaruan React di *root*. Jika elemen baru memiliki tipe dan *key* yang sama dengan elemen sebelumnya, struktur pohon akan diperbarui; jika tidak, akan memasang ulang pohon yang baru. ### `testRenderer.unmount()` {#testrendererunmount} @@ -134,7 +135,7 @@ Re-render the in-memory tree with a new root element. This simulates a React upd testRenderer.unmount() ``` -Unmount the in-memory tree, triggering the appropriate lifecycle events. +Melepas pohon dalam memori, memicu siklus hidup *event* yang sesuai. ### `testRenderer.getInstance()` {#testrenderergetinstance} @@ -142,7 +143,7 @@ Unmount the in-memory tree, triggering the appropriate lifecycle events. testRenderer.getInstance() ``` -Return the instance corresponding to the root element, if available. This will not work if the root element is a function component because they don't have instances. +Menghasilkan *instance* yang sesuai dengan elemen *root*, jika tersedia. Hal ini tidak akan berfungsi jika elemen *root* adalah *function component*, karena *function component* tidak memiliki *instance*. ### `testRenderer.root` {#testrendererroot} @@ -150,7 +151,7 @@ Return the instance corresponding to the root element, if available. This will n testRenderer.root ``` -Returns the root "test instance" object that is useful for making assertions about specific nodes in the tree. You can use it to find other "test instances" deeper below. +Menghasilkan objek *root* "uji *instance*" yang berguna untuk membuat pernyataan tentang *node* tertentu di pohon. Anda dapat menggunakannya untuk menemukan "uji *instance*" lainnya secara lebih dalam di bawah ini. ### `testInstance.find()` {#testinstancefind} @@ -158,7 +159,7 @@ Returns the root "test instance" object that is useful for making assertions abo testInstance.find(test) ``` -Find a single descendant test instance for which `test(testInstance)` returns `true`. If `test(testInstance)` does not return `true` for exactly one test instance, it will throw an error. +Menemukan turunan tunggal uji *instance* yang mana `test(testInstance)` menghasilkan nilai `true`. Jika `test(testInstance)` tidak menghasilkan nilai `true` untuk satu uji *instance*, hal ini akan melemparkan *error*. ### `testInstance.findByType()` {#testinstancefindbytype} @@ -166,7 +167,7 @@ Find a single descendant test instance for which `test(testInstance)` returns `t testInstance.findByType(type) ``` -Find a single descendant test instance with the provided `type`. If there is not exactly one test instance with the provided `type`, it will throw an error. +Menemukan turunan tunggal uji *instance* dengan berdasarkan `type` yang disediakan. Jika tidak ada satupun uji *instance* dengan `type` yang disediakan, hal ini akan melemparkan *error*. ### `testInstance.findByProps()` {#testinstancefindbyprops} @@ -174,7 +175,7 @@ Find a single descendant test instance with the provided `type`. If there is not testInstance.findByProps(props) ``` -Find a single descendant test instance with the provided `props`. If there is not exactly one test instance with the provided `props`, it will throw an error. +Menemukan turunan tunggal uji *instance* dengan berdasarkan `props` yang disediakan. Jika tidak ada satupun uji *instance* dengan `props` yang disediakan, hal ini akan melemparkan *error*. ### `testInstance.findAll()` {#testinstancefindall} @@ -182,7 +183,7 @@ Find a single descendant test instance with the provided `props`. If there is no testInstance.findAll(test) ``` -Find all descendant test instances for which `test(testInstance)` returns `true`. +Menemukan semua turunan uji *instance* yang mana `test(testInstance)` menghasilkan nilai `true`. ### `testInstance.findAllByType()` {#testinstancefindallbytype} @@ -190,7 +191,7 @@ Find all descendant test instances for which `test(testInstance)` returns `true` testInstance.findAllByType(type) ``` -Find all descendant test instances with the provided `type`. +Menemukan semua turunan uji *instance* dengan berdasarkan `type` yang disediakan. ### `testInstance.findAllByProps()` {#testinstancefindallbyprops} @@ -198,7 +199,7 @@ Find all descendant test instances with the provided `type`. testInstance.findAllByProps(props) ``` -Find all descendant test instances with the provided `props`. +Menemukan semua turunan uji *instance* dengan berdasarkan `props` yang disediakan. ### `testInstance.instance` {#testinstanceinstance} @@ -206,7 +207,7 @@ Find all descendant test instances with the provided `props`. testInstance.instance ``` -The component instance corresponding to this test instance. It is only available for class components, as function components don't have instances. It matches the `this` value inside the given component. +*Instance* dari komponen yang ada di uji *instance*. Hanya tersedia untuk *class component*, karena *function component* tidak memiliki *instance*. Hal Ini sama dengan nilai `this` di dalam komponen yang diberikan. ### `testInstance.type` {#testinstancetype} @@ -214,7 +215,7 @@ The component instance corresponding to this test instance. It is only available testInstance.type ``` -The component type corresponding to this test instance. For example, a `
@@ -189,25 +189,25 @@ function CustomTextInput(props) { } ``` -### Exposing DOM Refs to Parent Components {#exposing-dom-refs-to-parent-components} +### Mengekspos *Ref* DOM ke Komponen Induk {#exposing-dom-refs-to-parent-components} -In rare cases, you might want to have access to a child's DOM node from a parent component. This is generally not recommended because it breaks component encapsulation, but it can occasionally be useful for triggering focus or measuring the size or position of a child DOM node. +Pada sebagian kecil kasus, Anda mungkin ingin mendapatkan akses ke simpul DOM anak dari komponen induk. Hal ini tidak disarankan karena akan merusak enkapsulasi komponen, tetapi terkadang berguna untuk memicu fokus atau mengukur ukuran atau posisi simpul DOM anak. -While you could [add a ref to the child component](#adding-a-ref-to-a-class-component), this is not an ideal solution, as you would only get a component instance rather than a DOM node. Additionally, this wouldn't work with function components. +Walau Anda bisa [menambahkan *ref* ke *child component*](#adding-a-ref-to-a-class-component), ini bukan solusi yang ideal, karena Anda hanya akan mendapatkan instans komponen, bukan simpul DOM. Selain itu, hal ini tidak akan berfungsi dengan *function component*. -If you use React 16.3 or higher, we recommend to use [ref forwarding](/docs/forwarding-refs.html) for these cases. **Ref forwarding lets components opt into exposing any child component's ref as their own**. You can find a detailed example of how to expose a child's DOM node to a parent component [in the ref forwarding documentation](/docs/forwarding-refs.html#forwarding-refs-to-dom-components). +Jika Anda menggunakan React 16.3 atau yang lebih baru, kami sarankan untuk menggunakan [*ref forwarding*](/docs/forwarding-refs.html) untuk kasus semacam ini. ***Ref forwarding* memungkinkan komponen untuk memilih untuk mengekspos semua *ref* komponen anak sebagai miliknya sendiri**. Anda bisa menemukan contoh mendetail tentang cara mengekspos simpul DOM anak ke komponen induk [dalam dokumentasi *ref forwarding*](/docs/forwarding-refs.html#forwarding-refs-to-dom-components). -If you use React 16.2 or lower, or if you need more flexibility than provided by ref forwarding, you can use [this alternative approach](https://gist.github.com/gaearon/1a018a023347fe1c2476073330cc5509) and explicitly pass a ref as a differently named prop. +Jika Anda menggunakan React 16.2 atau yang lebih lawas, atau jika Anda membutuhkan lebih banyak fleksibilitas dibandingkan dengan yang disediakan oleh *ref forwarding*, Anda bisa menggunakan [pendekatan alternatif ini](https://gist.github.com/gaearon/1a018a023347fe1c2476073330cc5509) dan secara eksplisit mengoper sebuah *ref* sebagai *props* dengan nama yang berbeda. -When possible, we advise against exposing DOM nodes, but it can be a useful escape hatch. Note that this approach requires you to add some code to the child component. If you have absolutely no control over the child component implementation, your last option is to use [`findDOMNode()`](/docs/react-dom.html#finddomnode), but it is discouraged and deprecated in [`StrictMode`](/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage). +Jika dimungkinkan, kami sarankan untuk tidak mengekspos simpul DOM, walau bisa berguna sebagai jalan keluar. Perhatikan bahwa pendekatan ini membutuhkan tambahan kode pada komponen anak Jika Anda sama sekali tidak memiliki kontrol pada implementasi komponen anak, opsi terakhir Anda adalah menggunakan [`findDOMNode()`](/docs/react-dom.html#finddomnode). Tetapi hal ini tidak disarankan dan akan menjadi *deprecated* dalam [`StrictMode`](/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage). -### Callback Refs {#callback-refs} +### *Callback Ref* {#callback-refs} -React also supports another way to set refs called "callback refs", which gives more fine-grain control over when refs are set and unset. +React juga mendukung cara lain untuk menetapkan *ref* yang disebut sebagai *"callback ref"*, yang memberikan kontrol lebih mendetail kapan *ref* akan di-*set* dan di-*unset*. -Instead of passing a `ref` attribute created by `createRef()`, you pass a function. The function receives the React component instance or HTML DOM element as its argument, which can be stored and accessed elsewhere. +Alih-alih mengoper atribut `ref` yang dibuat oleh `createRef()`, Anda mengoper sebuah fungsi. Fungsi tersebut menerima instans komponen React atau elemen DOM HTML sebagai argumennya, yang bisa disimpan dan diakses di tempat lain. -The example below implements a common pattern: using the `ref` callback to store a reference to a DOM node in an instance property. +Contoh berikut mengimplementasikan sebuah pola umum: menggunakan *callback* `ref` untuk menyimpan rujukan ke simpul DOM dalam properti instans. ```javascript{5,7-9,11-14,19,29,34} class CustomTextInput extends React.Component { @@ -221,19 +221,19 @@ class CustomTextInput extends React.Component { }; this.focusTextInput = () => { - // Focus the text input using the raw DOM API + // Fokus pada input teks menggunakan API DOM mentah if (this.textInput) this.textInput.focus(); }; } componentDidMount() { - // autofocus the input on mount + // autofocus pada input saat mount this.focusTextInput(); } render() { - // Use the `ref` callback to store a reference to the text input DOM - // element in an instance field (for example, this.textInput). + // Gunakan callback `ref` untuk menyimpan rujukan ke elemen DOM + // input teks dalam field instans (misalnya, this.textInput). return (
@@ -251,9 +251,9 @@ class CustomTextInput extends React.Component { } ``` -React will call the `ref` callback with the DOM element when the component mounts, and call it with `null` when it unmounts. Refs are guaranteed to be up-to-date before `componentDidMount` or `componentDidUpdate` fires. +React akan memanggil *callback* `ref` dengan elemen DOM saat komponen dipasang dan memanggilnya dengan `null` saat dilepas. *Ref* dijamin untuk selalu diperbarui sebelum `componentDidMount` atau `componentDidUpdate` dijalankan. -You can pass callback refs between components like you can with object refs that were created with `React.createRef()`. +Anda bisa mengoper *callback ref* antarkomponen seperti halnya yang bisa Anda lakukan dengan *object ref* yang dibuat dengan `React.createRef()`. ```javascript{4,13} function CustomTextInput(props) { @@ -275,16 +275,16 @@ class Parent extends React.Component { } ``` -In the example above, `Parent` passes its ref callback as an `inputRef` prop to the `CustomTextInput`, and the `CustomTextInput` passes the same function as a special `ref` attribute to the ``. As a result, `this.inputElement` in `Parent` will be set to the DOM node corresponding to the `` element in the `CustomTextInput`. +Pada contoh di atas, `Parent` mengoper *callback ref*-nya sebagai *props* `inputRef` kepada `CustomTextInput` dan `CustomTextInput` mengoper fungsi yang sama sebagai atribut `ref` khusus kepada ``. Hasilnya, `this.inputElement` pada `Parent` akan disetel ke simpul DOM yang sesuai dengan elemen `` pada `CustomTextInput`. -### Legacy API: String Refs {#legacy-api-string-refs} +### API *Legacy*: *String Ref* {#legacy-api-string-refs} -If you worked with React before, you might be familiar with an older API where the `ref` attribute is a string, like `"textInput"`, and the DOM node is accessed as `this.refs.textInput`. We advise against it because string refs have [some issues](https://github.com/facebook/react/pull/8333#issuecomment-271648615), are considered legacy, and **are likely to be removed in one of the future releases**. +Jika sebelumnya Anda bekerja dengan React, Anda mungkin sudah mengenal API lawas dengan atribut `ref` berupa string, misalnya `"textInput"`, dan simpul DOM yang diakses dengan `this.refs.textInput`. Kami sarankan untuk tidak melakukannya karena *string ref* memiliki [beberapa masalah](https://github.com/facebook/react/pull/8333#issuecomment-271648615) dan dipertimbangkan sebagai *legacy*, serta **kemungkinan besar akan dihapus dalam salah satu rilis di masa mendatang**. -> Note +> Catatan > -> If you're currently using `this.refs.textInput` to access refs, we recommend using either the [callback pattern](#callback-refs) or the [`createRef` API](#creating-refs) instead. +> Jika saat ini Anda menggunakan `this.refs.textInput` untuk mengakses *ref*, kami sarankan untuk beralih menggunakan [*callback pattern*](#callback-refs) atau [API `createRef`](#creating-refs). -### Caveats with callback refs {#caveats-with-callback-refs} +### Kekurangan pada *callback ref* {#caveats-with-callback-refs} -If the `ref` callback is defined as an inline function, it will get called twice during updates, first with `null` and then again with the DOM element. This is because a new instance of the function is created with each render, so React needs to clear the old ref and set up the new one. You can avoid this by defining the `ref` callback as a bound method on the class, but note that it shouldn't matter in most cases. +Jika *callback* `ref` didefinisikan sebagai fungsi *inline*, fungsi ini akan dipanggil dua kali dalam proses pembaruan, yang pertama dengan argumen `null`, yang kedua dengan argumen elemen DOM. Ini terjadi karena instans baru dari fungsi akan dibuat dalam setiap proses *render*, karena React harus membersihkan *ref* yang lama dan menyiapkan yang baru. Anda bisa menghindari hal ini dengan mendefinisikan *callback* `ref` sebagau *bound method* pada kelas, tetapi perhatikan bahwa dalam sebagian besar kasus hal ini tidak berpengaruh. From b90088021daa2a0fdc172574993550d149305651 Mon Sep 17 00:00:00 2001 From: lunmay <28674102+lunmay@users.noreply.github.com> Date: Thu, 28 Feb 2019 15:25:00 +0100 Subject: [PATCH 03/10] Translated Portals --- content/docs/portals.md | 81 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/content/docs/portals.md b/content/docs/portals.md index 650121396..82938e44a 100644 --- a/content/docs/portals.md +++ b/content/docs/portals.md @@ -1,24 +1,24 @@ --- id: portals -title: Portals +title: Portal permalink: docs/portals.html --- -Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. +Portal menyediakan cara utama untuk me-*render* anak ke dalam simpul DOM yang berada di luar hierarki komponen induk. ```js ReactDOM.createPortal(child, container) ``` -The first argument (`child`) is any [renderable React child](/docs/react-component.html#render), such as an element, string, or fragment. The second argument (`container`) is a DOM element. +Argumen pertama (`child`) berupa [anak React yang bisa di-*render*](/docs/react-component.html#render), misalnya sebuah elemen, string, atau *fragment*. Argumen kedua (`container`) merupakan elemen DOM. -## Usage {#usage} +## Penggunaan {#usage} -Normally, when you return an element from a component's render method, it's mounted into the DOM as a child of the nearest parent node: +Umumnya saat Anda mengembalikan sebuah elemen dari *method* *render* komponen, elemen tersebut dipasang ke DOM sebagai anak pada simpul induk terdekat: ```js{4,6} render() { - // React mounts a new div and renders the children into it + // React memasang div baru dan me-render anaknya kepadanya return (
{this.props.children} @@ -27,12 +27,13 @@ render() { } ``` -However, sometimes it's useful to insert a child into a different location in the DOM: +Akan tetapi terkadang ada gunanya untuk menyisipkan sebuah anak ke lokasi yang berbeda dalam DOM: ```js{6} render() { - // React does *not* create a new div. It renders the children into `domNode`. - // `domNode` is any valid DOM node, regardless of its location in the DOM. + // React *tidak* membuat div baru. React me-render anak ke dalam `domNode`. + // `domNode` berupa simpul DOM apa saja yang valid, tidak tergantung pada + // lokasinya dalam DOM. return ReactDOM.createPortal( this.props.children, domNode @@ -40,21 +41,21 @@ render() { } ``` -A typical use case for portals is when a parent component has an `overflow: hidden` or `z-index` style, but you need the child to visually "break out" of its container. For example, dialogs, hovercards, and tooltips. +Penggunaan umum untuk portal adalah ketika komponen induk memiliki gaya `overflow: hidden` atau `z-index`, tetapi Anda harus "memisahkan" anak secara visual dari kontainernya. Misalnya pada dialog, *hovercard*, atau *tooltip*. -> Note: +> Catatan: > -> When working with portals, remember that [managing keyboard focus](/docs/accessibility.html#programmatically-managing-focus) becomes very important. +> Saat bekerja dengan portal, perhatikan bahwa [mengelola fokus papan ketik](/docs/accessibility.html#programmatically-managing-focus) menjadi sangat penting. > -> For modal dialogs, ensure that everyone can interact with them by following the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal). +> Untuk dialog modal, pastikan semua pihak bisa berinteraksi dengannya dengan mengikuti [WAI-ARIA Modal Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal). -[**Try it on CodePen**](https://codepen.io/gaearon/pen/yzMaBd) +[**Coba di CodePen**](https://codepen.io/gaearon/pen/yzMaBd) -## Event Bubbling Through Portals {#event-bubbling-through-portals} +## *Event Bubbling* lewat Portal {#event-bubbling-through-portals} -Even though a portal can be anywhere in the DOM tree, it behaves like a normal React child in every other way. Features like context work exactly the same regardless of whether the child is a portal, as the portal still exists in the *React tree* regardless of position in the *DOM tree*. +Walau sebuah portal bisa berada di mana saja dalam pohon DOM, portal tersebut berperilaku seperti halnya anak React yang normal. Fitur seperti *context work* bekerja sama persis tanpa tergantung apakah sebuah anak adalah sebuah portal, karena portal masih berada dalam *pohon React* tanpa memandang posisinya dalam *pohon DOM*. -This includes event bubbling. An event fired from inside a portal will propagate to ancestors in the containing *React tree*, even if those elements are not ancestors in the *DOM tree*. Assuming the following HTML structure: +Ini mencakup *event bubbling*. Sebuah *event* yang dijalankan dari dalam portal akan dipropagasikan ke induknya dalam *pohon React* yang memuatnya, walau elemen tersebut bukan merupakan induk dalam *pohon DOM*. Misalnya pada struktur HTML berikut: ```html @@ -65,10 +66,10 @@ This includes event bubbling. An event fired from inside a portal will propagate ``` -A `Parent` component in `#app-root` would be able to catch an uncaught, bubbling event from the sibling node `#modal-root`. +Komponen `Parent` pada `#app-root` akan bisa menangkap *event bubbling* yang belum ditangkap dari simpul sederajat `#modal-root`. ```js{28-31,42-49,53,61-63,70-71,74} -// These two containers are siblings in the DOM +// Kedua kontainer berikut sederajat dalam DOM const appRoot = document.getElementById('app-root'); const modalRoot = document.getElementById('modal-root'); @@ -79,14 +80,14 @@ class Modal extends React.Component { } componentDidMount() { - // The portal element is inserted in the DOM tree after - // the Modal's children are mounted, meaning that children - // will be mounted on a detached DOM node. If a child - // component requires to be attached to the DOM tree - // immediately when mounted, for example to measure a - // DOM node, or uses 'autoFocus' in a descendant, add - // state to Modal and only render the children when Modal - // is inserted in the DOM tree. + // Elemen portal disisipkan dalam pohon DOM setelah + // anak dari Modal dipasang, yang berarti anak tersebut + // akan dipasang pada simpul DOM yang terpisah. Jika + // komponen anak harus disematkan ke dalam pohon DOM + // segera setelah dipasang, misalnya untuk mengukur dimensi + // simpul DOM, atau menggunakan 'autoFocus' pada turunannya, + // tambahkan state pada Modal dan hanya render para anak saat + // Modal disisipkan dalam pohon DOM. modalRoot.appendChild(this.el); } @@ -110,9 +111,9 @@ class Parent extends React.Component { } handleClick() { - // This will fire when the button in Child is clicked, - // updating Parent's state, even though button - // is not direct descendant in the DOM. + // Ini akan dijalankan ketika tombol pada Child diklik, + // memperbarui state Parent, walau tombol tersebut + // bukan turunan langsung dalam DOM. this.setState(state => ({ clicks: state.clicks + 1 })); @@ -121,12 +122,12 @@ class Parent extends React.Component { render() { return (
-

Number of clicks: {this.state.clicks}

+

Jumlah klik: {this.state.clicks}

- Open up the browser DevTools - to observe that the button - is not a child of the div - with the onClick handler. + Buka DevTools browser + untuk mengamati bahwa tombol + bukan anak dari div + pada handler onClick.

@@ -137,11 +138,11 @@ class Parent extends React.Component { } function Child() { - // The click event on this button will bubble up to parent, - // because there is no 'onClick' attribute defined + // Event klik pada tombol ini akan meluap ke induk, + // karena tidak ada atribut 'onClick' yang didefinisikan return (
- +
); } @@ -149,6 +150,6 @@ function Child() { ReactDOM.render(, appRoot); ``` -[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBWpE) +[**Coba di CodePen**](https://codepen.io/gaearon/pen/jGBWpE) -Catching an event bubbling up from a portal in a parent component allows the development of more flexible abstractions that are not inherently reliant on portals. For example, if you render a `` component, the parent can capture its events regardless of whether it's implemented using portals. +Menangkap *event bubbling* yang meluap dari portal pada komponen induk mengizinkan pengembangan abstraksi yang lebih fleksibel yang tidak mengandalkan portal. Misalnya jika Anda me-*render* komponen ``, induk bisa menangkap *event*-nya tanpa tergantung apakah diimplementasikan dengan portal atau tidak. From fe6c8d1f9cd2e1b36669f8a0ee9f0c3fd7e46aa2 Mon Sep 17 00:00:00 2001 From: lunmay <28674102+lunmay@users.noreply.github.com> Date: Thu, 28 Feb 2019 16:09:11 +0100 Subject: [PATCH 04/10] Translated React Without ES6 --- content/docs/react-without-es6.md | 91 ++++++++++++++++--------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/content/docs/react-without-es6.md b/content/docs/react-without-es6.md index 8b54d0981..720c8d602 100644 --- a/content/docs/react-without-es6.md +++ b/content/docs/react-without-es6.md @@ -1,36 +1,36 @@ --- id: react-without-es6 -title: React Without ES6 +title: React Tanpa ES6 permalink: docs/react-without-es6.html --- -Normally you would define a React component as a plain JavaScript class: +Umumnya Anda mendefinisikan komponen React sebagai kelas JavaScript biasa: ```javascript class Greeting extends React.Component { render() { - return

Hello, {this.props.name}

; + return

Halo {this.props.name}

; } } ``` -If you don't use ES6 yet, you may use the `create-react-class` module instead: +Jika Anda belum menggunakan ES6, Anda bisa menggunakan modul `create-react-class`: ```javascript var createReactClass = require('create-react-class'); var Greeting = createReactClass({ render: function() { - return

Hello, {this.props.name}

; + return

Halo {this.props.name}

; } }); ``` -The API of ES6 classes is similar to `createReactClass()` with a few exceptions. +API untuk kelas ES6 mirip dengan `createReactClass()`, dengan beberapa pengecualian. -## Declaring Default Props {#declaring-default-props} +## Mendeklarasikan *Props* *Default* {#declaring-default-props} -With functions and ES6 classes `defaultProps` is defined as a property on the component itself: +Dengan kelas dan fungsi ES6, `defaultProps` didefinisikan sebagai properti komponennya sendiri: ```javascript class Greeting extends React.Component { @@ -38,17 +38,17 @@ class Greeting extends React.Component { } Greeting.defaultProps = { - name: 'Mary' + name: 'Maria' }; ``` -With `createReactClass()`, you need to define `getDefaultProps()` as a function on the passed object: +Dengan `createReactClass()`, Anda harus mendefinisikan `getDefaultProps()` sebagai fungsi pada objek yang dioperkan: ```javascript var Greeting = createReactClass({ getDefaultProps: function() { return { - name: 'Mary' + name: 'Maria' }; }, @@ -57,9 +57,9 @@ var Greeting = createReactClass({ }); ``` -## Setting the Initial State {#setting-the-initial-state} +## Menyetel *State* Awal {#setting-the-initial-state} -In ES6 classes, you can define the initial state by assigning `this.state` in the constructor: +Pada kelas ES6, Anda bisa mendefinisikan *state* awal dengan menetapkan `this.state` pada konstruktor: ```javascript class Counter extends React.Component { @@ -71,7 +71,7 @@ class Counter extends React.Component { } ``` -With `createReactClass()`, you have to provide a separate `getInitialState` method that returns the initial state: +Dengan `createReactClass()`, Anda harus menyediakan *method* `getInitialState` terpisah yang mengembalikan *state* awal: ```javascript var Counter = createReactClass({ @@ -82,16 +82,16 @@ var Counter = createReactClass({ }); ``` -## Autobinding {#autobinding} +## *Autobinding* {#autobinding} -In React components declared as ES6 classes, methods follow the same semantics as regular ES6 classes. This means that they don't automatically bind `this` to the instance. You'll have to explicitly use `.bind(this)` in the constructor: +Pada komponen React yang dideklarasikan sebagai kelas ES6, *method* mengikuti semantik yang sama seperti kelas ES6 reguler. Ini berarti *method* tersebut tidak secara otomatis mem-*bind* `this` kepada instans. Anda harus secara eksplisit menggunakan `.bind(this)` pada konstruktor: ```javascript class SayHello extends React.Component { constructor(props) { super(props); - this.state = {message: 'Hello!'}; - // This line is important! + this.state = {message: 'Halo!'}; + // Baris berikut penting! this.handleClick = this.handleClick.bind(this); } @@ -100,22 +100,23 @@ class SayHello extends React.Component { } render() { - // Because `this.handleClick` is bound, we can use it as an event handler. + // Karena `this.handleClick` telah di-bind, kita bisa menggunakannya + // sebagai event handler. return ( ); } } ``` -With `createReactClass()`, this is not necessary because it binds all methods: +Dengan `createReactClass()`, hal tersebut tidak diperlukan karena semua *method* akan di-*bind*: ```javascript var SayHello = createReactClass({ getInitialState: function() { - return {message: 'Hello!'}; + return {message: 'Halo!'}; }, handleClick: function() { @@ -125,26 +126,26 @@ var SayHello = createReactClass({ render: function() { return ( ); } }); ``` -This means writing ES6 classes comes with a little more boilerplate code for event handlers, but the upside is slightly better performance in large applications. +Ini berarti penulisan dengan kelas ES6 disertai dengan kode *boilerplate* untuk *event handler* tetapi manfaatnya adalah kinerja yang sedikit lebih baik dalam aplikasi yang besar. -If the boilerplate code is too unattractive to you, you may enable the **experimental** [Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/) syntax proposal with Babel: +Jika kode *boilerplate* sangat tidak menarik bagi Anda, Anda bisa mengaktifkan sintaksis [*Class Property*](https://babeljs.io/docs/plugins/transform-class-properties/) yang bersifat **eksperimental** dengan Babel: ```javascript class SayHello extends React.Component { constructor(props) { super(props); - this.state = {message: 'Hello!'}; + this.state = {message: 'Halo!'}; } - // WARNING: this syntax is experimental! - // Using an arrow here binds the method: + // PERINGATAN: sintalsis ini bersifat eksperimental! + // Menggunakan *arrow* akan mem-bind method: handleClick = () => { alert(this.state.message); } @@ -152,34 +153,34 @@ class SayHello extends React.Component { render() { return ( ); } } ``` -Please note that the syntax above is **experimental** and the syntax may change, or the proposal might not make it into the language. +Perhatikan bahwa sintaksis di atas bersifat **eksperimental** dan sintaksis mungkin akan berubah, atau proposal ini tidak akan disertakan dalam bahasa. -If you'd rather play it safe, you have a few options: +Jika Anda ingin bermain pada area yang aman, Anda memiliki beberapa opsi: -* Bind methods in the constructor. -* Use arrow functions, e.g. `onClick={(e) => this.handleClick(e)}`. -* Keep using `createReactClass`. +* Mem-*bind* *method* dalam konstruktor. +* Gunakan *arrow function*, misalnya `onClick={(e) => this.handleClick(e)}`. +* Terus gunakan `createReactClass`. -## Mixins {#mixins} +## Mixin {#mixins} ->**Note:** +>**Catatan:** > ->ES6 launched without any mixin support. Therefore, there is no support for mixins when you use React with ES6 classes. +>ES6 diluncurkan tanpa adanya dukungan *mixin*. Oleh sebab itu, tidak ada dukungan untuk *mixin* saat Anda menggunakan React dengan kelas ES6. > ->**We also found numerous issues in codebases using mixins, [and don't recommend using them in the new code](/blog/2016/07/13/mixins-considered-harmful.html).** +>**Kami juga menemukan banyak masalah pada kode dasar yang menggunakan *mixin*, [dan tidak menyarankan untuk menggunakannya untuk kode yang baru](/blog/2016/07/13/mixins-considered-harmful.html).** > ->This section exists only for the reference. +>Bagian berikut hanya digunakan untuk rujukan. -Sometimes very different components may share some common functionality. These are sometimes called [cross-cutting concerns](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass` lets you use a legacy `mixins` system for that. +Terkadang komponen yang sangat berbeda bisa berbagi fungsionalitas yang sama. Hal ini terkadang disebut sebagai [*cross-cutting concern*](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass` memungkinkan Anda untuk menggunakan sistem `mixin` yang bersifat *legacy* untuk hal tersebut. -One common use case is a component wanting to update itself on a time interval. It's easy to use `setInterval()`, but it's important to cancel your interval when you don't need it anymore to save memory. React provides [lifecycle methods](/docs/react-component.html#the-component-lifecycle) that let you know when a component is about to be created or destroyed. Let's create a simple mixin that uses these methods to provide an easy `setInterval()` function that will automatically get cleaned up when your component is destroyed. +Salah satu kasus penggunaan yang umum adalah sebuah komponen ingin memperbarui dirinya sendiri secara periodik. Sangat mudah untuk menggunakan `setInterval()`, tetapi sangat penting untuk membatalkan interval jika Anda tidak membutuhkannya lagi untuk menghemat memori. React menyediakan [*lifecycle method*](/docs/react-component.html#the-component-lifecycle) yang bisa memberi tahu Anda kapan komponen akan diciptakan atau dihancurkan. Sebagai contoh, mari kita buat *mixin* yang sederhana yang menggunakan *method* berikut untuk menyediakan fungsi `setInterval()` yang mudah, yang akan dibersihkan secara otomatis ketika komponen Anda dihancurkan. ```javascript var SetIntervalMixin = { @@ -197,12 +198,12 @@ var SetIntervalMixin = { var createReactClass = require('create-react-class'); var TickTock = createReactClass({ - mixins: [SetIntervalMixin], // Use the mixin + mixins: [SetIntervalMixin], // Gunakan mixin getInitialState: function() { return {seconds: 0}; }, componentDidMount: function() { - this.setInterval(this.tick, 1000); // Call a method on the mixin + this.setInterval(this.tick, 1000); // Panggil method pada mixin }, tick: function() { this.setState({seconds: this.state.seconds + 1}); @@ -210,7 +211,7 @@ var TickTock = createReactClass({ render: function() { return (

- React has been running for {this.state.seconds} seconds. + React telah berjalan selama {this.state.seconds} detik.

); } @@ -222,4 +223,4 @@ ReactDOM.render( ); ``` -If a component is using multiple mixins and several mixins define the same lifecycle method (i.e. several mixins want to do some cleanup when the component is destroyed), all of the lifecycle methods are guaranteed to be called. Methods defined on mixins run in the order mixins were listed, followed by a method call on the component. +Jika komponen menggunakan beberapa *mixin* dan beberapa *mixin* mendefinisikan *lifecycle method* yang sama (beberapa *mixin* ingin melakukan pembersihan ketika komponen dihancurkan), semua *lifecycle method* dijamin untuk dipanggil. *Method* yang didefiniskan pada *mixin* dijalankan secara berurutan sesuai dengan dengan proses pendaftarannya, diikuti dengan pemanggilan *method* pada komponen. From 2289fc45bb7c63f3eefff340b365d38bf5927a7e Mon Sep 17 00:00:00 2001 From: lunmay <28674102+lunmay@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:05:36 +0100 Subject: [PATCH 05/10] Translated Uncontrolled Component --- content/docs/uncontrolled-components.md | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/content/docs/uncontrolled-components.md b/content/docs/uncontrolled-components.md index 10b6eab28..73d55eebe 100644 --- a/content/docs/uncontrolled-components.md +++ b/content/docs/uncontrolled-components.md @@ -1,14 +1,14 @@ --- id: uncontrolled-components -title: Uncontrolled Components +title: Uncontrolled Component permalink: docs/uncontrolled-components.html --- -In most cases, we recommend using [controlled components](/docs/forms.html) to implement forms. In a controlled component, form data is handled by a React component. The alternative is uncontrolled components, where form data is handled by the DOM itself. +Pada sebagian besar kasus, kami sarankan untuk menggunakan [*controlled component*](/docs/forms.html) untuk mengimpementasikan *form*. Pada *controlled component*, *form data* ditangani oleh komponen React. Cara alternatifnya adalah menggunakan *uncontrolled component*, dengan *form data* ditangani oleh DOM-nya sendiri. -To write an uncontrolled component, instead of writing an event handler for every state update, you can [use a ref](/docs/refs-and-the-dom.html) to get form values from the DOM. +Untuk menulis *uncontrolled component*, alih-alih menulis *event handler* untuk setiap pembaruan *state*, Anda bisa [menggunakan *ref*](/docs/refs-and-the-dom.html) untuk mendapatkan nilai *form* dari DOM. -For example, this code accepts a single name in an uncontrolled component: +Misalnya, kode berikut menerima sebuah nama dari sebuah *uncontrolled component*: ```javascript{5,9,18} class NameForm extends React.Component { @@ -19,7 +19,7 @@ class NameForm extends React.Component { } handleSubmit(event) { - alert('A name was submitted: ' + this.input.current.value); + alert('Sebuah nama telah dikirim: ' + this.input.current.value); event.preventDefault(); } @@ -27,56 +27,56 @@ class NameForm extends React.Component { return (
- +
); } } ``` -[**Try it on CodePen**](https://codepen.io/gaearon/pen/WooRWa?editors=0010) +[**Coba di CodePen**](https://codepen.io/gaearon/pen/WooRWa?editors=0010) -Since an uncontrolled component keeps the source of truth in the DOM, it is sometimes easier to integrate React and non-React code when using uncontrolled components. It can also be slightly less code if you want to be quick and dirty. Otherwise, you should usually use controlled components. +Oleh karena *uncontrolled component* menyimpan sumber kebenaran dalam DOM, terkadang lebih mudah untuk mengintegrasikan kode React dan non-React jika menggunakan *uncontrolled component*. Ini juga berarti lebih sedikit kode jika Anda menginginkan solusi cepat walau tak rapi. Selain itu pada umumnya Anda harus menggunakan *controlled component*. -If it's still not clear which type of component you should use for a particular situation, you might find [this article on controlled versus uncontrolled inputs](https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/) to be helpful. +Jika masih belum jelas jenis komponen mana yang harus Anda gunakan untuk situasi tertentu, mungkin [artikel tentang *controlled input* versus *uncontrolled input*](https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/) bisa membantu. -### Default Values {#default-values} +### Nilai *Default* {#default-values} -In the React rendering lifecycle, the `value` attribute on form elements will override the value in the DOM. With an uncontrolled component, you often want React to specify the initial value, but leave subsequent updates uncontrolled. To handle this case, you can specify a `defaultValue` attribute instead of `value`. +Pada *lifecycle rendering* React, atribut `value` pada elemen *form* akan menimpa nilai pada DOM. Dengan *uncontrolled component*, sering kali Anda menginginkan React untuk menentukan nilai awal tetapi pembaruan berikutnya dilakukan secara *uncontrolled*. Untuk menangani kasus ini, Anda bisa menentukan atribut `defaultValue` alih-alih menggunakan `value`. ```javascript{7} render() { return (
- +
); } ``` -Likewise, `` and `` support `defaultChecked`, and `