Skip to content

Commit 47b3f75

Browse files
aris-uuresir014mhaidarhanif
authored
docs: translate react-dom -> flushSync (#578)
Co-authored-by: Resi Respati <resir014@gmail.com> Co-authored-by: M Haidar Hanif <git@mhaidarhanif.com>
1 parent 0d2244d commit 47b3f75

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/content/reference/react-dom/flushSync.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: flushSync
44

55
<Pitfall>
66

7-
Using `flushSync` is uncommon and can hurt the performance of your app.
7+
Penggunaan `flushSync` tidak umum dan dapat menyebabkan penurunan kinerja aplikasi Anda.
88

99
</Pitfall>
1010

1111
<Intro>
1212

13-
`flushSync` lets you force React to flush any updates inside the provided callback synchronously. This ensures that the DOM is updated immediately.
13+
`flushSync` dapat memaksa React untuk menge-*flush* pembaruan dalam *callback* yang diberikan secara sinkron. Ini memastikan bahwa DOM diperbarui dengan segera.
1414

1515
```js
1616
flushSync(callback)
@@ -22,11 +22,11 @@ flushSync(callback)
2222

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Referensi {/*reference*/}
2626

2727
### `flushSync(callback)` {/*flushsync*/}
2828

29-
Call `flushSync` to force React to flush any pending work and update the DOM synchronously.
29+
Panggil `flushSync` untuk memaksa React menge-*flush* pekerjaan tertunda dan memperbarui DOM secara sinkon.
3030

3131
```js
3232
import { flushSync } from 'react-dom';
@@ -36,50 +36,50 @@ flushSync(() => {
3636
});
3737
```
3838

39-
Most of the time, `flushSync` can be avoided. Use `flushSync` as last resort.
39+
Seringnya, `flushSync` dapat dihindari. Gunakan `flushSync` sebagai pilihan terakhir.
4040

41-
[See more examples below.](#usage)
41+
[Lihat lebih banyak contoh di bawah.](#usage)
4242

43-
#### Parameters {/*parameters*/}
43+
#### Parameter {/*parameters*/}
4444

4545

46-
* `callback`: A function. React will immediately call this callback and flush any updates it contains synchronously. It may also flush any pending updates, or Effects, or updates inside of Effects. If an update suspends as a result of this `flushSync` call, the fallbacks may be re-shown.
46+
* `callback`: Sebuah fungsi. React akan langsung memanggil *callback* ini dan menge-*flush* pembaruan di dalamnya secara sinkron. React juga dapat menge-*flush* pembaruan tertunda, atau *Effects*, atau pembaruan di dalam *Effects*. Jika sebuah pembaruan tertunda karena pemanggilan `flushSync` ini, *fallback*-nya dapat ditampilkan kembali.
4747

48-
#### Returns {/*returns*/}
48+
#### Kembalian {/*returns*/}
4949

50-
`flushSync` returns `undefined`.
50+
`flushSync` mengembalikan `undefined`.
5151

52-
#### Caveats {/*caveats*/}
52+
#### Catatan penting {/*caveats*/}
5353

54-
* `flushSync` can significantly hurt performance. Use sparingly.
55-
* `flushSync` may force pending Suspense boundaries to show their `fallback` state.
56-
* `flushSync` may run pending effects and synchronously apply any updates they contain before returning.
57-
* `flushSync` may flush updates outside the callback when necessary to flush the updates inside the callback. For example, if there are pending updates from a click, React may flush those before flushing the updates inside the callback.
54+
* `flushSync` dapat menurunkan performa secara signifikan. Jangan gunakan terlalu sering.
55+
* `flushSync` dapat memaksa batas *Suspense* tertunda untuk menampilkan *state* `fallback`-nya.
56+
* `flushSync` dapat menjakankan *effects* tertunda dan secara sinkron menerapkan pembaruan di dalamnya sebelum mengembalikan.
57+
* `flushSync` dapat menge-*flush* pembaruan di luar *callback* ketika perlu untuk menge-*flush* pembaruan di dalam *callback*. Misalnya, jika ada pembaruan tertunda dari sebuah klik, React dapat menge-*flush* pembaruan tersebut sebelum menge-*flush* pembaruan di dalam *callback*.
5858

5959
---
6060

61-
## Usage {/*usage*/}
61+
## Penggunaan {/*usage*/}
6262

63-
### Flushing updates for third-party integrations {/*flushing-updates-for-third-party-integrations*/}
63+
### Menge-*flush* pembaruan untuk integrasi pihak ketiga {/*flushing-updates-for-third-party-integrations*/}
6464

65-
When integrating with third-party code such as browser APIs or UI libraries, it may be necessary to force React to flush updates. Use `flushSync` to force React to flush any <CodeStep step={1}>state updates</CodeStep> inside the callback synchronously:
65+
Saat berintegrasi dengan kode pihak ketiga seperti API browser atau pustaka UI, mungkin akan diperlukan untuk memaksa React menge-*flush* pembaruan. Gunakan `flushSync` untuk memaksa react menge-*flush* <CodeStep step={1}>pembaruan *state*</CodeStep> di dalam callback secara sinkron:
6666

6767
```js [[1, 2, "setSomething(123)"]]
6868
flushSync(() => {
6969
setSomething(123);
7070
});
71-
// By this line, the DOM is updated.
71+
// Pada baris ini, DOM sudah diperbarui.
7272
```
7373

74-
This ensures that, by the time the next line of code runs, React has already updated the DOM.
74+
Ini memastikan bahwa, pada saat baris berikutnya berjalan, React sudah memperbarui DOM.
7575

76-
**Using `flushSync` is uncommon, and using it often can significantly hurt the performance of your app.** If your app only uses React APIs, and does not integrate with third-party libraries, `flushSync` should be unnecessary.
76+
**Penggunaan `flushSync` tidak umum, dan menggunakannya dengan sering dapat menurunkan performa aplikasi Anda secara signifikan.** Jika aplikasi Anda hanya menggunakan API React, dan tidak berintegrasi dengan pustaka pihak ketiga, `flushSync` seharusnya tidak perlu digunakan.
7777

78-
However, it can be helpful for integrating with third-party code like browser APIs.
78+
Namun, `flushSync` dapat berguna untuk berintegrasi dengan kode pihak ketiga seperti API peramban.
7979

80-
Some browser APIs expect results inside of callbacks to be written to the DOM synchronously, by the end of the callback, so the browser can do something with the rendered DOM. In most cases, React handles this for you automatically. But in some cases it may be necessary to force a synchronous update.
80+
Beberapa API peramban mengekspektasikan hasil di dalam *callback* ditulis ke DOM secara sinkron di akhir *callback*, sehingga peramban dapat melakukan sesuatu dengan DOM yang telah di-*render*. Dalam kebanyakan kasus, React menangani ini untuk Anda secara otomatis. Namun, dalam beberapa kasus, mungkin tidak diperlukan untuk memaksakan pembaruan sinkron.
8181

82-
For example, the browser `onbeforeprint` API allows you to change the page immediately before the print dialog opens. This is useful for applying custom print styles that allow the document to display better for printing. In the example below, you use `flushSync` inside of the `onbeforeprint` callback to immediately "flush" the React state to the DOM. Then, by the time the print dialog opens, `isPrinting` displays "yes":
82+
Sebagai contoh, API peramban `onbeforeprint` memungkinkan Anda untuk mengubah halaman dengan segera sebelum dialog cetak (*print dialog*) terbuka. Ini berguna untuk menerapkan gaya cetak tersuai (*custom print styles*) yang memungkinkan dokumen untuk tampil lebih baik untuk dicetak. Dalam contoh di bawah, Anda menggunakan `flushSync` di dalam *callback* `onbeforeprint` untuk dengan segera "menge-*flush*" *state* React ke DOM. Kemudian, pada saat dialog cetak terbuka, `isPrinting` akan menampilkan "yes":
8383

8484
<Sandpack>
8585

@@ -122,12 +122,12 @@ export default function PrintApp() {
122122

123123
</Sandpack>
124124

125-
Without `flushSync`, when the print dialog will display `isPrinting` as "no". This is because React batches the updates asynchronously and the print dialog is displayed before the state is updated.
125+
Tanpa `flushSync`, dialog cetak akan menampilkan `isPrinting` sebagai "no". Ini terjadi karena React mengelompokkan (*batch*) pembaruan secara asinkron dan dialog cetak ditampilkan sebelum *state* diperbarui.
126126

127127
<Pitfall>
128128

129-
`flushSync` can significantly hurt performance, and may unexpectedly force pending Suspense boundaries to show their fallback state.
129+
`flushSync` dapat menurunkan performa secara signifikan, dan mungkin tiba-tiba memaksa batas *Suspense* yang tertunda untuk menampilkan *state* *fallback*-nya.
130130

131-
Most of the time, `flushSync` can be avoided, so use `flushSync` as a last resort.
131+
Seringnya, `flushSync` dapat dihindari, maka gunakan `flushSync` sebagai pilihan terakhir.
132132

133133
</Pitfall>

0 commit comments

Comments
 (0)