Skip to content

Commit b7a58ea

Browse files
authored
Merge pull request #880 from reactjs/tr/useEffectEvent
Translate "useEffectEvent"
2 parents 3f7993d + ad08cd6 commit b7a58ea

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/content/reference/react/useEffectEvent.md

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

55
<Intro>
66

7-
`useEffectEvent` is a React Hook that lets you extract non-reactive logic from your Effects into a reusable function called an [Effect Event](/learn/separating-events-from-effects#declaring-an-effect-event).
7+
`useEffectEvent` は、エフェクトから非リアクティブなロジックを、[エフェクトイベント (Effect Event)](/learn/separating-events-from-effects#declaring-an-effect-event) と呼ばれる再利用可能な関数へと抽出できるようにする React フックです。
88

99
```js
1010
const onSomething = useEffectEvent(callback)
@@ -14,11 +14,11 @@ const onSomething = useEffectEvent(callback)
1414

1515
<InlineToc />
1616

17-
## Reference {/*reference*/}
17+
## リファレンス {/*reference*/}
1818

1919
### `useEffectEvent(callback)` {/*useeffectevent*/}
2020

21-
Call `useEffectEvent` at the top level of your component to declare an Effect Event. Effect Events are functions you can call inside Effects, such as `useEffect`:
21+
コンポーネントのトップレベルで `useEffectEvent` を呼び出し、エフェクトイベントを宣言します。エフェクトイベントは、`useEffect` などのエフェクト内から呼び出すことができる関数です。
2222

2323
```js {4-6,11}
2424
import { useEffectEvent, useEffect } from 'react';
@@ -41,33 +41,33 @@ function ChatRoom({ roomId, theme }) {
4141
}
4242
```
4343

44-
[See more examples below.](#usage)
44+
[さらに例を見る](#usage)
4545

46-
#### Parameters {/*parameters*/}
46+
#### 引数 {/*parameters*/}
4747

48-
- `callback`: A function containing the logic for your Effect Event. When you define an Effect Event with `useEffectEvent`, the `callback` always accesses the latest values from props and state when it is invoked. This helps avoid issues with stale closures.
48+
- `callback`: エフェクトイベントのロジックを含む関数。`useEffectEvent` でエフェクトイベントを定義すると、`callback` は常に、呼び出された瞬間の props state の最新の値にアクセスします。これにより、古くなったクロージャに関する問題を回避できます。
4949

50-
#### Returns {/*returns*/}
50+
#### 返り値 {/*returns*/}
5151

52-
Returns an Effect Event function. You can call this function inside `useEffect`, `useLayoutEffect`, or `useInsertionEffect`.
52+
エフェクトイベント関数を返します。この関数は `useEffect``useLayoutEffect`、あるいは `useInsertionEffect` 内で呼び出すことができます。
5353

54-
#### Caveats {/*caveats*/}
54+
#### 注意点 {/*caveats*/}
5555

56-
- **Only call inside Effects:** Effect Events should only be called within Effects. Define them just before the Effect that uses them. Do not pass them to other components or hooks. The [`eslint-plugin-react-hooks`](/reference/eslint-plugin-react-hooks) linter (version 6.1.1 or higher) will enforce this restriction to prevent calling Effect Events in the wrong context.
57-
- **Not a dependency shortcut:** Do not use `useEffectEvent` to avoid specifying dependencies in your Effect's dependency array. This can hide bugs and make your code harder to understand. Prefer explicit dependencies or use refs to compare previous values if needed.
58-
- **Use for non-reactive logic:** Only use `useEffectEvent` to extract logic that does not depend on changing values.
56+
- **エフェクト内でのみ呼び出す**:エフェクトイベントはエフェクト内からのみ呼び出すべきです。それを使用するエフェクトの直前で定義するようにしてください。他のコンポーネントやフックに渡さないでください。[`eslint-plugin-react-hooks`](/reference/eslint-plugin-react-hooks) リンタ(バージョン 6.1.1 以降)はこの制約を強制することで、誤った使い方でのエフェクトイベントの呼び出しを防止します。
57+
- **依存配列を避けるためのものではない**:エフェクトの依存配列で依存値を指定すること自体を避けるために `useEffectEvent` を使用してはいけません。バグが隠蔽され、コードが理解しにくくなります。明示的に依存値を書くか、必要に応じて ref を使用して以前の値と比較するようにしてください。
58+
- **非リアクティブなロジックだけに使う**`useEffectEvent` は、値の変化に依存しないロジックを抽出する目的にのみ使用してください。
5959

6060
___
6161

62-
## Usage {/*usage*/}
62+
## 使用法 {/*usage*/}
6363

64-
### Reading the latest props and state {/*reading-the-latest-props-and-state*/}
64+
### 最新の props state を読み取る {/*reading-the-latest-props-and-state*/}
6565

66-
Typically, when you access a reactive value inside an Effect, you must include it in the dependency array. This makes sure your Effect runs again whenever that value changes, which is usually the desired behavior.
66+
通常、エフェクト内でリアクティブな値にアクセスする場合は、それを依存配列に含める必要があります。これにより、その値が変化するたびにエフェクトが再実行されます。通常はこれが望ましい動作です。
6767

68-
But in some cases, you may want to read the most recent props or state inside an Effect without causing the Effect to re-run when those values change.
68+
しかし場合によっては、これらの値が変化してもエフェクトを再実行させることなく、エフェクト内で最新の props state を読み取りたいことがあります。
6969

70-
To [read the latest props or state](/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events) in your Effect, without making those values reactive, include them in an Effect Event.
70+
エフェクト内で[最新の props state を読み取る](/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events)際に、それらの値をリアクティブにしないようにするには、エフェクトイベント内に含めます。
7171

7272
```js {7-9,12}
7373
import { useEffect, useContext, useEffectEvent } from 'react';
@@ -88,7 +88,7 @@ function Page({ url }) {
8888
}
8989
```
9090

91-
In this example, the Effect should re-run after a render when `url` changes (to log the new page visit), but it should **not** re-run when `numberOfItems` changes. By wrapping the logging logic in an Effect Event, `numberOfItems` becomes non-reactive. It's always read from the latest value without triggering the Effect.
91+
この例では、`url` が変化したあとの再レンダーではエフェクトが再実行されるべきですが(新しいページの訪問を記録するため)、`numberOfItems` が変化した場合には再実行される**べきではありません**。ログ記録のロジックをエフェクトイベントでラップすることで、`numberOfItems` はリアクティブではなくなります。エフェクトをトリガすることなく、常に最新の値が読み取られます。
9292

93-
You can pass reactive values like `url` as arguments to the Effect Event to keep them reactive while accessing the latest non-reactive values inside the event.
93+
`url` のようなリアクティブな値は、エフェクトイベントに引数として渡すことで、それらをリアクティブに保ちながら、イベント内で最新の非リアクティブな値にもアクセスすることができます。
9494

0 commit comments

Comments
 (0)