Skip to content

Commit 29866af

Browse files
committed
translate useOptimistic.md to Ukrainian
1 parent 683d261 commit 29866af

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/content/reference/react/useOptimistic.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useOptimistic
44

55
<Intro>
66

7-
`useOptimistic` is a React Hook that lets you optimistically update the UI.
7+
`useOptimistic` — це хук, який дозволяє оптимістично (попередньо) оновлювати UI.
88

99
```js
1010
const [optimisticState, addOptimistic] = useOptimistic(state, updateFn);
@@ -16,13 +16,13 @@ title: useOptimistic
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## Опис {/*reference*/}
2020

2121
### `useOptimistic(state, updateFn)` {/*use*/}
2222

23-
`useOptimistic` is a React Hook that lets you show a different state while an async action is underway. It accepts some state as an argument and returns a copy of that state that can be different during the duration of an async action such as a network request. You provide a function that takes the current state and the input to the action, and returns the optimistic state to be used while the action is pending.
23+
Хук `useOptimistic` дає змогу відображати особливий стан протягом виконання асинхронної дії. Він приймає певний стан як аргумент і повертає копію цього стану, яка може відрізнятися від переданого стану протягом виконання асинхронної дії, наприклад, мережевого запиту. Ви описуєте функцію, яка отримує поточний стан і вхідні дані для дії, та повертає «оптимістичний» стан, який буде відображатися, поки дія триває.
2424

25-
This state is called the "optimistic" state because it is usually used to immediately present the user with the result of performing an action, even though the action actually takes time to complete.
25+
Цей стан називається «оптимістичним», тому що зазвичай використовується, щоб показати користувачеві очікуваний результат одразу, навіть якщо на завершення дії потрібен певний час.
2626

2727
```js
2828
import { useOptimistic } from 'react';
@@ -32,35 +32,35 @@ function AppContainer() {
3232
state,
3333
// updateFn
3434
(currentState, optimisticValue) => {
35-
// merge and return new state
36-
// with optimistic value
35+
// об’єднайте і поверніть новий стан
36+
// з оптимістичним значенням
3737
}
3838
);
3939
}
4040
```
4141

42-
[See more examples below.](#usage)
42+
[Перегляньте більше прикладів нижче.](#usage)
4343

44-
#### Parameters {/*parameters*/}
44+
#### Параметри {/*parameters*/}
4545

46-
* `state`: the value to be returned initially and whenever no action is pending.
47-
* `updateFn(currentState, optimisticValue)`: a function that takes the current state and the optimistic value passed to `addOptimistic` and returns the resulting optimistic state. It must be a pure function. `updateFn` takes in two parameters. The `currentState` and the `optimisticValue`. The return value will be the merged value of the `currentState` and `optimisticValue`.
46+
* `state`: значення, яке повертається перший раз та кожного разу, коли немає дії, що виконується.
47+
* `updateFn(currentState, optimisticValue)`: функція, яка приймає поточний стан і оптимістичне значення, передане до `addOptimistic`, та повертає розрахований оптимістичний стан. Повинна бути чистою функцією. `updateFn` приймає два параметри: `currentState` і `optimisticValue`. Функція повертає значення, що об'єднує `currentState` і `optimisticValue`.
4848

4949

50-
#### Returns {/*returns*/}
50+
#### Результат {/*returns*/}
5151

52-
* `optimisticState`: The resulting optimistic state. It is equal to `state` unless an action is pending, in which case it is equal to the value returned by `updateFn`.
53-
* `addOptimistic`: `addOptimistic` is the dispatching function to call when you have an optimistic update. It takes one argument, `optimisticValue`, of any type and will call the `updateFn` with `state` and `optimisticValue`.
52+
* `optimisticState`: розрахований оптимістичний стан. Він дорівнює `state` допоки немає дії, що виконується, інакше він дорівнює значенню, яке повертає `updateFn`.
53+
* `addOptimistic`: `addOptimistic` — це функція, яку потрібно викликати для оптимістичного оновлення. Вона приймає один аргумент `optimisticValue` будь-якого типу та викликає `updateFn` із `state` і `optimisticValue`.
5454

5555
---
5656

57-
## Usage {/*usage*/}
57+
## Використання {/*usage*/}
5858

59-
### Optimistically updating forms {/*optimistically-updating-with-forms*/}
59+
### Оптимістичне оновлення форм {/*optimistically-updating-with-forms*/}
6060

61-
The `useOptimistic` Hook provides a way to optimistically update the user interface before a background operation, like a network request, completes. In the context of forms, this technique helps to make apps feel more responsive. When a user submits a form, instead of waiting for the server's response to reflect the changes, the interface is immediately updated with the expected outcome.
61+
Хук `useOptimistic` дає змогу оптимістично оновлювати інтерфейс доки завершиться фонова операція, наприклад мережевий запит. У контексті форм такий підхід створює відчуття швидшої реакції застосунків. Коли користувач надсилає форму, замість очікування відповіді від сервера, інтерфейс одразу оновлюється і відображає очікуваний результат.
6262

63-
For example, when a user types a message into the form and hits the "Send" button, the `useOptimistic` Hook allows the message to immediately appear in the list with a "Sending..." label, even before the message is actually sent to a server. This "optimistic" approach gives the impression of speed and responsiveness. The form then attempts to truly send the message in the background. Once the server confirms the message has been received, the "Sending..." label is removed.
63+
Наприклад, коли користувач вводить повідомлення у форму й натискає кнопку «Надіслати», хук `useOptimistic` дозволяє одразу відобразити це повідомлення у списку з позначкою «Надсилання...», ще до того, як воно реально буде відправлене на сервер. Такий «оптимістичний» підхід створює відчуття швидкої роботи застосунку. Після цього форма справді намагається надіслати повідомлення у фоновому режимі. Коли сервер підтвердить, що повідомлення було отримано, позначка «Надсилання...» зникне.
6464

6565
<Sandpack>
6666

@@ -92,13 +92,13 @@ function Thread({ messages, sendMessageAction }) {
9292
return (
9393
<>
9494
<form action={formAction} ref={formRef}>
95-
<input type="text" name="message" placeholder="Hello!" />
96-
<button type="submit">Send</button>
95+
<input type="text" name="message" placeholder="Вітаю!" />
96+
<button type="submit">Надіслати</button>
9797
</form>
9898
{optimisticMessages.map((message, index) => (
9999
<div key={index}>
100100
{message.text}
101-
{!!message.sending && <small> (Sending...)</small>}
101+
{!!message.sending && <small> (Надсилання...)</small>}
102102
</div>
103103
))}
104104

@@ -108,7 +108,7 @@ function Thread({ messages, sendMessageAction }) {
108108

109109
export default function App() {
110110
const [messages, setMessages] = useState([
111-
{ text: "Hello there!", sending: false, key: 1 }
111+
{ text: "Привіт!", sending: false, key: 1 }
112112
]);
113113
async function sendMessageAction(formData) {
114114
const sentMessage = await deliverMessage(formData.get("message"));

0 commit comments

Comments
 (0)