You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react/useOptimistic.md
+16-16
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ canary: true
5
5
6
6
<Canary>
7
7
8
-
The `useOptimistic`Hook is currently only available in React's Canary and experimental channels. Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
@@ -23,13 +23,13 @@ The `useOptimistic` Hook is currently only available in React's Canary and exper
23
23
24
24
---
25
25
26
-
## Reference {/*reference*/}
26
+
## リファレンス {/*reference*/}
27
27
28
28
### `useOptimistic(state, updateFn)` {/*use*/}
29
29
30
-
`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.
30
+
`useOptimistic`は、何らかの非同期アクションが進行中の間だけ、異なる state を表示するための React フックです。ある state を引数として受け取ってそのコピーを返しますが、ネットワークリクエストなどの非同期アクションが実行中の場合に異なる値を返すことができます。現在の state とアクションへの入力を受け取り、アクション実行中に使用される楽観的 state を返すような関数を渡します。
31
31
32
-
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.
32
+
このような state が「楽観的」state と呼ばれるのは、実際にはアクションの完了には時間がかかるにも関わらず、そのアクションの実行結果をユーザに即座に提示するために通常使用されるものだからです。
33
33
34
34
```js
35
35
import { useOptimistic } from'react';
@@ -46,28 +46,28 @@ function AppContainer() {
46
46
}
47
47
```
48
48
49
-
[See more examples below.](#usage)
49
+
[さらに例を見る](#usage)
50
50
51
-
#### Parameters {/*parameters*/}
51
+
#### 引数 {/*parameters*/}
52
52
53
-
*`state`: the value to be returned initially and whenever no action is pending.
54
-
*`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`.
53
+
*`state`: 初期状態や、実行中のアクションが存在しない場合に返される値。
54
+
*`updateFn(currentState, optimisticValue)`: state の現在値と、`addOptimistic`に渡された楽観的更新に使用する値 (optimistic value) を受け取り、結果としての楽観的 state を返す関数。純関数でなければなりません。`updateFn`は `currentState`と `optimisticValue` の 2 つの引数を受け取ります。返り値は `currentState`に`optimisticValue` の値を反映させたものとなります。
55
55
56
56
57
-
#### Returns {/*returns*/}
57
+
#### 返り値 {/*returns*/}
58
58
59
-
*`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`.
60
-
*`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`.
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.
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.
0 commit comments