Skip to content

Commit 2551636

Browse files
authored
Merge pull request #983 from reactjs/tr/react-compiler-directives
Translate React Compiler directive-related articles
2 parents 87695fd + 937f6d4 commit 2551636

3 files changed

Lines changed: 125 additions & 125 deletions

File tree

‎src/content/reference/react-compiler/directives.md‎

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Directives
2+
title: ディレクティブ
33
---
44

55
<Intro>
6-
React Compiler directives are special string literals that control whether specific functions are compiled.
6+
React Compiler のディレクティブは、特定の関数をコンパイルするかどうかを制御する特別な文字列リテラルです。
77
</Intro>
88

99
```js
@@ -17,29 +17,29 @@ function MyComponent() {
1717

1818
---
1919

20-
## Overview {/*overview*/}
20+
## 概要 {/*overview*/}
2121

22-
React Compiler directives provide fine-grained control over which functions are optimized by the compiler. They are string literals placed at the beginning of a function body or at the top of a module.
22+
React Compiler のディレクティブを使用することで、コンパイラがどの関数を最適化するかを細かく制御できます。ディレクティブは、関数本体の先頭またはモジュールの先頭に配置する文字列リテラルです。
2323

24-
### Available directives {/*available-directives*/}
24+
### 利用可能なディレクティブ {/*available-directives*/}
2525

26-
* **[`"use memo"`](/reference/react-compiler/directives/use-memo)** - Opts a function into compilation
27-
* **[`"use no memo"`](/reference/react-compiler/directives/use-no-memo)** - Opts a function out of compilation
26+
* **[`"use memo"`](/reference/react-compiler/directives/use-memo)** - 関数をコンパイル対象に含める
27+
* **[`"use no memo"`](/reference/react-compiler/directives/use-no-memo)** - 関数をコンパイル対象から除外する
2828

29-
### Quick comparison {/*quick-comparison*/}
29+
### 比較表 {/*quick-comparison*/}
3030

31-
| Directive | Purpose | When to use |
31+
| ディレクティブ | 目的 | 使用する場面 |
3232
|-----------|---------|-------------|
33-
| [`"use memo"`](/reference/react-compiler/directives/use-memo) | Force compilation | When using `annotation` mode or to override `infer` mode heuristics |
34-
| [`"use no memo"`](/reference/react-compiler/directives/use-no-memo) | Prevent compilation | Debugging issues or working with incompatible code |
33+
| [`"use memo"`](/reference/react-compiler/directives/use-memo) | コンパイルを強制 | `annotation` モードを使用する場合、または `infer` モードのヒューリスティックを上書きする場合 |
34+
| [`"use no memo"`](/reference/react-compiler/directives/use-no-memo) | コンパイルを防止 | 問題をデバッグする場合、または互換性のないコードを扱う場合 |
3535

3636
---
3737

38-
## Usage {/*usage*/}
38+
## 使用法 {/*usage*/}
3939

40-
### Function-level directives {/*function-level*/}
40+
### 関数レベルのディレクティブ {/*function-level*/}
4141

42-
Place directives at the beginning of a function to control its compilation:
42+
関数のコンパイルを制御するには、その関数の先頭にディレクティブを配置します。
4343

4444
```js
4545
// Opt into compilation
@@ -55,9 +55,9 @@ function UnoptimizedComponent() {
5555
}
5656
```
5757
58-
### Module-level directives {/*module-level*/}
58+
### モジュールレベルのディレクティブ {/*module-level*/}
5959
60-
Place directives at the top of a file to affect all functions in that module:
60+
モジュール内のすべての関数に適用するには、ファイルの先頭にディレクティブを配置します。
6161
6262
```js
6363
// At the very top of the file
@@ -79,21 +79,21 @@ function Component3() {
7979
}
8080
```
8181
82-
### Compilation modes interaction {/*compilation-modes*/}
82+
### コンパイルモードとの関係 {/*compilation-modes*/}
8383
84-
Directives behave differently depending on your [`compilationMode`](/reference/react-compiler/compilationMode):
84+
ディレクティブの動作は、[`compilationMode`](/reference/react-compiler/compilationMode) によって異なります。
8585
86-
* **`annotation` mode**: Only functions with `"use memo"` are compiled
87-
* **`infer` mode**: Compiler decides what to compile, directives override decisions
88-
* **`all` mode**: Everything is compiled, `"use no memo"` can exclude specific functions
86+
* **`annotation` モード**:`"use memo"` がある関数のみをコンパイルする
87+
* **`infer` モード**:コンパイラがコンパイル対象を決定し、ディレクティブがその決定を上書きする
88+
* **`all` モード**:すべてをコンパイルし、`"use no memo"` で特定の関数を除外できる
8989
9090
---
9191
92-
## Best practices {/*best-practices*/}
92+
## ベストプラクティス {/*best-practices*/}
9393
94-
### Use directives sparingly {/*use-sparingly*/}
94+
### ディレクティブは必要な場合にのみ使用する {/*use-sparingly*/}
9595
96-
Directives are escape hatches. Prefer configuring the compiler at the project level:
96+
ディレクティブは避難ハッチです。プロジェクトレベルでコンパイラを設定することを優先してください。
9797
9898
```js
9999
// ✅ Good - project-wide configuration
@@ -112,9 +112,9 @@ function SpecialCase() {
112112
}
113113
```
114114
115-
### Document directive usage {/*document-usage*/}
115+
### ディレクティブの使用理由を記録する {/*document-usage*/}
116116
117-
Always explain why a directive is used:
117+
ディレクティブを使用する理由を必ず説明してください。
118118
119119
```js
120120
// ✅ Good - clear explanation
@@ -130,14 +130,14 @@ function Mystery() {
130130
}
131131
```
132132
133-
### Plan for removal {/*plan-removal*/}
133+
### 削除する予定を立てておく {/*plan-removal*/}
134134
135-
Opt-out directives should be temporary:
135+
オプトアウト用のディレクティブは一時的なものにしてください。
136136
137-
1. Add the directive with a TODO comment
138-
2. Create a tracking issue
139-
3. Fix the underlying problem
140-
4. Remove the directive
137+
1. ディレクティブを追加する際は TODO コメント付きにする
138+
2. 追跡用の issue を作成する
139+
3. 大元にある問題を修正する
140+
4. ディレクティブを削除する
141141
142142
```js
143143
function TemporaryWorkaround() {
@@ -148,11 +148,11 @@ function TemporaryWorkaround() {
148148
149149
---
150150
151-
## Common patterns {/*common-patterns*/}
151+
## よくあるパターン {/*common-patterns*/}
152152
153-
### Gradual adoption {/*gradual-adoption*/}
153+
### 段階的導入 {/*gradual-adoption*/}
154154
155-
When adopting the React Compiler in a large codebase:
155+
大規模なコードベースに React Compiler を導入する場合は、次のようにします。
156156
157157
```js
158158
// Start with annotation mode
@@ -176,23 +176,23 @@ function ProblematicComponent() {
176176
177177
---
178178
179-
## Troubleshooting {/*troubleshooting*/}
179+
## トラブルシューティング {/*troubleshooting*/}
180180
181-
For specific issues with directives, see the troubleshooting sections in:
181+
ディレクティブに関する具体的な問題については、以下のトラブルシューティングセクションを参照してください。
182182
183-
* [`"use memo"` troubleshooting](/reference/react-compiler/directives/use-memo#troubleshooting)
184-
* [`"use no memo"` troubleshooting](/reference/react-compiler/directives/use-no-memo#troubleshooting)
183+
* [`"use memo"` のトラブルシューティング](/reference/react-compiler/directives/use-memo#troubleshooting)
184+
* [`"use no memo"` のトラブルシューティング](/reference/react-compiler/directives/use-no-memo#troubleshooting)
185185
186-
### Common issues {/*common-issues*/}
186+
### よくある問題 {/*common-issues*/}
187187
188-
1. **Directive ignored**: Check placement (must be first) and spelling
189-
2. **Compilation still happens**: Check `ignoreUseNoForget` setting
190-
3. **Module directive not working**: Ensure it's before all imports
188+
1. **ディレクティブが無視される**:配置(先頭である必要があります)とスペルを確認する
189+
2. **コンパイルが引き続き実行される**:`ignoreUseNoForget` の設定を確認する
190+
3. **モジュールのディレクティブが動作しない**:すべてのインポートより前にあることを確認する
191191
192192
---
193193
194-
## See also {/*see-also*/}
194+
## 関連項目 {/*see-also*/}
195195
196-
* [`compilationMode`](/reference/react-compiler/compilationMode) - Configure how the compiler chooses what to optimize
197-
* [`Configuration`](/reference/react-compiler/configuration) - Full compiler configuration options
198-
* [React Compiler documentation](/learn/react-compiler) - Getting started guide
196+
* [`compilationMode`](/reference/react-compiler/compilationMode) - コンパイラが最適化対象を選択する方法を設定する
197+
* [設定](/reference/react-compiler/configuration) - コンパイラのすべての設定オプション
198+
* [React Compiler のドキュメント](/learn/react-compiler) - 入門ガイド
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
22
title: "use memo"
3-
titleForTitleTag: "'use memo' directive"
3+
titleForTitleTag: "'use memo' ディレクティブ"
44
---
55

66
<Intro>
77

8-
`"use memo"` marks a function for React Compiler optimization.
8+
`"use memo"` は、関数を React Compiler による最適化の対象としてマークします。
99

1010
</Intro>
1111

1212
<Note>
1313

14-
In most cases, you don't need `"use memo"`. It's primarily needed in `annotation` mode where you must explicitly mark functions for optimization. In `infer` mode, the compiler automatically detects components and hooks by their naming patterns (PascalCase for components, `use` prefix for hooks). If a component or hook isn't being compiled in `infer` mode, you should fix its naming convention rather than forcing compilation with `"use memo"`.
14+
ほとんどの場合、`"use memo"` は必要ありません。これは主に、最適化する関数を明示的にマークする必要がある `annotation` モードで使用するものです。`infer` モードでは、コンパイラが命名パターン(コンポーネントは PascalCase、フックは `use` プレフィックス)に基づいてコンポーネントやフックを自動的に検出します。`infer` モードでコンポーネントやフックがコンパイルされない場合、`"use memo"` でコンパイルを強制するのではなく、命名規則のほうを修正してください。
1515

1616
</Note>
1717

1818
<InlineToc />
1919

2020
---
2121

22-
## Reference {/*reference*/}
22+
## リファレンス {/*reference*/}
2323

2424
### `"use memo"` {/*use-memo*/}
2525

26-
Add `"use memo"` at the beginning of a function to mark it for React Compiler optimization.
26+
関数を React Compiler による最適化の対象としてマークするには、その関数の先頭に `"use memo"` を追加します。
2727

2828
```js {1}
2929
function MyComponent() {
@@ -32,34 +32,34 @@ function MyComponent() {
3232
}
3333
```
3434

35-
When a function contains `"use memo"`, the React Compiler will analyze and optimize it during build time. The compiler will automatically memoize values and components to prevent unnecessary re-computations and re-renders.
35+
関数に `"use memo"` が含まれている場合、React Compiler はビルド時にその関数を解析して最適化します。コンパイラは値やコンポーネントを自動的にメモ化し、不要な再計算や再レンダーを防ぎます。
3636

37-
#### Caveats {/*caveats*/}
37+
#### 注意点 {/*caveats*/}
3838

39-
* `"use memo"` must be at the very beginning of a function body, before any imports or other code (comments are OK).
40-
* The directive must be written with double or single quotes, not backticks.
41-
* The directive must exactly match `"use memo"`.
42-
* Only the first directive in a function is processed; additional directives are ignored.
43-
* The effect of the directive depends on your [`compilationMode`](/reference/react-compiler/compilationMode) setting.
39+
* `"use memo"` は、インポートやその他のコードより前、関数本体の冒頭に置く必要があります(コメントは置くことができます)。
40+
* ディレクティブはバッククォートではなく、ダブルクォートまたはシングルクォートで記述する必要があります。
41+
* ディレクティブ文字列は `"use memo"` に完全に合致する必要があります。
42+
* 関数内では最初のディレクティブのみが処理され、後続のディレクティブは無視されます。
43+
* ディレクティブの効果は、[`compilationMode`](/reference/react-compiler/compilationMode) の設定によって異なります。
4444

45-
### How `"use memo"` marks functions for optimization {/*how-use-memo-marks*/}
45+
### `"use memo"` が関数を最適化対象としてマークする仕組み {/*how-use-memo-marks*/}
4646

47-
In a React app that uses the React Compiler, functions are analyzed at build time to determine if they can be optimized. By default, the compiler automatically infers which components to memoize, but this can depend on your [`compilationMode`](/reference/react-compiler/compilationMode) setting if you've set it.
47+
React Compiler を使用する React アプリでは、関数を最適化できるか判断するためにビルド時に解析が行われます。デフォルトでは、コンパイラがメモ化するコンポーネントを自動的に推論しますが、[`compilationMode`](/reference/react-compiler/compilationMode) を設定している場合は、その設定によって動作が変わることがあります。
4848

49-
`"use memo"` explicitly marks a function for optimization, overriding the default behavior:
49+
`"use memo"` はデフォルトの動作を上書きし、関数を最適化対象として明示的にマークします。
5050

51-
* In `annotation` mode: Only functions with `"use memo"` are optimized
52-
* In `infer` mode: The compiler uses heuristics, but `"use memo"` forces optimization
53-
* In `all` mode: Everything is optimized by default, making `"use memo"` redundant
51+
* `annotation` モード:`"use memo"` がある関数のみが最適化される
52+
* `infer` モード:コンパイラはヒューリスティックを使用するが、`"use memo"` により最適化が強制される
53+
* `all` モード:デフォルトですべてが最適化されるため、`"use memo"` は冗長になる
5454

55-
The directive creates a clear boundary in your codebase between optimized and non-optimized code, giving you fine-grained control over the compilation process.
55+
このディレクティブにより、コードベース内で最適化されるコードとされないコードとの境界が明確になり、コンパイルプロセスを細かく制御できます。
5656

57-
### When to use `"use memo"` {/*when-to-use*/}
57+
### `"use memo"` を使用する場面 {/*when-to-use*/}
5858

59-
You should consider using `"use memo"` when:
59+
次のような場合は、`"use memo"` の使用を検討してください。
6060

61-
#### You're using annotation mode {/*annotation-mode-use*/}
62-
In `compilationMode: 'annotation'`, the directive is required for any function you want optimized:
61+
#### annotation モードを使用している場合 {/*annotation-mode-use*/}
62+
`compilationMode: 'annotation'` では、最適化したいすべての関数にディレクティブが必要です。
6363

6464
```js
6565
// ✅ This component will be optimized
@@ -74,8 +74,8 @@ function SimpleWrapper() {
7474
}
7575
```
7676

77-
#### You're gradually adopting React Compiler {/*gradual-adoption*/}
78-
Start with `annotation` mode and selectively optimize stable components:
77+
#### React Compiler を段階的に導入中の場合 {/*gradual-adoption*/}
78+
`annotation` モードから始め、安定したコンポーネントを選択的に最適化します。
7979

8080
```js
8181
// Start by optimizing leaf components
@@ -93,11 +93,11 @@ function ButtonGroup({ buttons }) {
9393

9494
---
9595

96-
## Usage {/*usage*/}
96+
## 使用法 {/*usage*/}
9797

98-
### Working with different compilation modes {/*compilation-modes*/}
98+
### さまざまなコンパイルモードで使用する {/*compilation-modes*/}
9999

100-
The behavior of `"use memo"` changes based on your compiler configuration:
100+
`"use memo"` の動作は、コンパイラの設定によって変わります。
101101

102102
```js
103103
// babel.config.js
@@ -110,7 +110,7 @@ module.exports = {
110110
};
111111
```
112112

113-
#### Annotation mode {/*annotation-mode-example*/}
113+
#### annotation モード {/*annotation-mode-example*/}
114114
```js
115115
// ✅ Optimized with "use memo"
116116
function ProductCard({ product }) {
@@ -124,7 +124,7 @@ function ProductList({ products }) {
124124
}
125125
```
126126

127-
#### Infer mode (default) {/*infer-mode-example*/}
127+
#### infer モード(デフォルト) {/*infer-mode-example*/}
128128
```js
129129
// Automatically memoized because this is named like a Component
130130
function ComplexDashboard({ data }) {
@@ -137,21 +137,21 @@ function simpleDisplay({ text }) {
137137
}
138138
```
139139

140-
In `infer` mode, the compiler automatically detects components and hooks by their naming patterns (PascalCase for components, `use` prefix for hooks). If a component or hook isn't being compiled in `infer` mode, you should fix its naming convention rather than forcing compilation with `"use memo"`.
140+
`infer` モードでは、コンパイラが命名パターン(コンポーネントは PascalCase、フックは `use` プレフィックス)に基づいてコンポーネントやフックを自動的に検出します。`infer` モードでコンポーネントやフックがコンパイルされない場合は、`"use memo"` でコンパイルを強制するのではなく、命名規則のほうを修正してください。
141141

142142
---
143143

144-
## Troubleshooting {/*troubleshooting*/}
144+
## トラブルシューティング {/*troubleshooting*/}
145145

146-
### Verifying optimization {/*verifying-optimization*/}
146+
### 最適化を確認する {/*verifying-optimization*/}
147147

148-
To confirm your component is being optimized:
148+
コンポーネントが最適化されていることを確認するには、次のようにします。
149149

150-
1. Check the compiled output in your build
151-
2. Use React DevTools to check for Memo ✨ badge
150+
1. ビルド内のコンパイル済み出力を確認する
151+
2. React DevTools を使用して Memo ✨ バッジを確認する
152152

153-
### See also {/*see-also*/}
153+
### 関連項目 {/*see-also*/}
154154

155-
* [`"use no memo"`](/reference/react-compiler/directives/use-no-memo) - Opt out of compilation
156-
* [`compilationMode`](/reference/react-compiler/compilationMode) - Configure compilation behavior
157-
* [React Compiler](/learn/react-compiler) - Getting started guide
155+
* [`"use no memo"`](/reference/react-compiler/directives/use-no-memo) - コンパイルからオプトアウトする
156+
* [`compilationMode`](/reference/react-compiler/compilationMode) - コンパイルの動作を設定する
157+
* [React Compiler](/learn/react-compiler) - 入門ガイド

0 commit comments

Comments
 (0)