Skip to content

Commit 9caac24

Browse files
docs: translate flushSync.md to Русский
1 parent 2958f53 commit 9caac24

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 28 additions & 28 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+
Использование `flushSync` встречается редко и может ухудшить производительность вашего приложения.
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` позволяет принудительно выполнить все обновления React внутри предоставленного колбэка синхронно. Это гарантирует немедленное обновление DOM.
1414

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

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Справочник {/*reference*/}
2626

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

29-
Call `flushSync` to force React to flush any pending work and update the DOM synchronously.
29+
Вызовите `flushSync`, чтобы принудительно выполнить все ожидающие операции React и синхронно обновить DOM.
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+
В большинстве случаев `flushSync` можно избежать. Используйте `flushSync` в крайнем случае.
4040

41-
[See more examples below.](#usage)
41+
[См. примеры ниже.](#usage)
4242

43-
#### Parameters {/*parameters*/}
43+
#### Параметры {/*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`: Функция. React немедленно вызовет этот колбэк и синхронно выполнит все обновления, содержащиеся в нём. Он также может выполнить любые ожидающие обновления, эффекты или обновления внутри эффектов. Если обновление приостанавливается в результате этого вызова `flushSync`, могут снова отобразиться запасные варианты (`fallback`).
4747

48-
#### Returns {/*returns*/}
48+
#### Возвращаемое значение {/*returns*/}
4949

50-
`flushSync` returns `undefined`.
50+
`flushSync` возвращает `undefined`.
5151

52-
#### Caveats {/*caveats*/}
52+
#### Ограничения {/*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` может значительно ухудшить производительность. Используйте с осторожностью.
55+
* `flushSync` может принудительно отобразить запасное состояние (`fallback`) для ожидающих границ Suspense.
56+
* `flushSync` может выполнить ожидающие эффекты и синхронно применить любые обновления, содержащиеся в них, перед возвратом.
57+
* `flushSync` может выполнить обновления вне колбэка при необходимости для выполнения обновлений внутри колбэка. Например, если есть ожидающие обновления от клика, React может выполнить их перед выполнением обновлений внутри колбэка.
5858

5959
---
6060

61-
## Usage {/*usage*/}
61+
## Использование {/*usage*/}
6262

63-
### Flushing updates for third-party integrations {/*flushing-updates-for-third-party-integrations*/}
63+
### Принудительное выполнение обновлений для сторонних интеграций {/*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+
При интеграции со сторонним кодом, таким как API браузера или библиотеки пользовательского интерфейса, может потребоваться принудительно выполнить обновления React. Используйте `flushSync`, чтобы принудительно выполнить все <CodeStep step={1}>обновления состояния</CodeStep> внутри колбэка синхронно:
6666

6767
```js [[1, 2, "setSomething(123)"]]
6868
flushSync(() => {
6969
setSomething(123);
7070
});
71-
// By this line, the DOM is updated.
71+
// К этой строке DOM будет обновлен.
7272
```
7373

74-
This ensures that, by the time the next line of code runs, React has already updated the DOM.
74+
Это гарантирует, что к моменту выполнения следующей строки кода React уже обновит 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+
**Использование `flushSync` встречается редко, и частое его использование может значительно ухудшить производительность вашего приложения.** Если ваше приложение использует только API React и не интегрируется со сторонними библиотеками, `flushSync` не потребуется.
7777

78-
However, it can be helpful for integrating with third-party code like browser APIs.
78+
Однако он может быть полезен для интеграции со сторонним кодом, таким как API браузера.
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+
Некоторые API браузера ожидают, что результаты внутри колбэков будут записаны в DOM синхронно, к концу колбэка, чтобы браузер мог что-то сделать с отрисованным DOM. В большинстве случаев React обрабатывает это автоматически. Но в некоторых случаях может потребоваться принудительное синхронное обновление.
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+
Например, API браузера `onbeforeprint` позволяет изменить страницу непосредственно перед открытием диалогового окна печати. Это полезно для применения пользовательских стилей печати, которые позволяют документу лучше отображаться при печати. В приведенном ниже примере вы используете `flushSync` внутри колбэка `onbeforeprint`, чтобы немедленно "сбросить" состояние React в DOM. Затем, к моменту открытия диалогового окна печати, `isPrinting` отображает "yes":
8383

8484
<Sandpack>
8585

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

123123
</Sandpack>
124124

125-
Without `flushSync`, 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+
Без `flushSync` диалоговое окно печати отобразит `isPrinting` как "no". Это связано с тем, что React пакетно обрабатывает обновления асинхронно, и диалоговое окно печати отображается до обновления состояния.
126126

127127
<Pitfall>
128128

129-
`flushSync` can significantly hurt performance, and may unexpectedly force pending Suspense boundaries to show their fallback state.
129+
`flushSync` может значительно ухудшить производительность и неожиданно принудительно отобразить запасное состояние для ожидающих границ Suspense.
130130

131-
Most of the time, `flushSync` can be avoided, so use `flushSync` as a last resort.
131+
В большинстве случаев `flushSync` можно избежать, поэтому используйте `flushSync` в качестве последнего средства.
132132

133-
</Pitfall>
133+
</Pitfall>

0 commit comments

Comments
 (0)