Skip to content

Commit 3bbb186

Browse files
smikitkypotato4d
authored andcommitted
Translate invalid-hook-call-warning (#131)
1 parent 6f427e9 commit 3bbb186

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

content/warnings/invalid-hook-call-warning.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ layout: single
44
permalink: warnings/invalid-hook-call-warning.html
55
---
66

7-
You are probably here because you got the following error message:
7+
このページを見ているのは、恐らく以下のエラーメッセージが出たからでしょう。
88

9-
> Hooks can only be called inside the body of a function component.
9+
> Hooks can only be called inside the body of a function component.(フックは関数コンポーネントの本体でしか呼び出せません)
1010
11-
There are three common reasons you might be seeing it:
11+
このエラーを目にする理由としてよくあるものは 3 つです。
1212

13-
1. You might have **mismatching versions** of React and React DOM.
14-
2. You might be **breaking the [Rules of Hooks](/docs/hooks-rules.html)**.
15-
3. You might have **more than one copy of React** in the same app.
13+
1. React と React DOM の**バージョンがマッチしていない**
14+
2. **[フックのルール](/docs/hooks-rules.html)**に違反している。
15+
3. 同じアプリ内に **2 つ以上の React のコピー**が含まれている。
1616

17-
Let's look at each of these cases.
17+
それぞれのケースについて見てみましょう。
1818

19-
## Mismatching Versions of React and React DOM {#mismatching-versions-of-react-and-react-dom}
19+
## React React DOM のバージョン不整合 {#mismatching-versions-of-react-and-react-dom}
2020

21-
You might be using a version of `react-dom` (< 16.8.0) or `react-native` (< 0.60) that doesn't yet support Hooks. You can run `npm ls react-dom` or `npm ls react-native` in your application folder to check which version you're using. If you find more than one of them, this might also create problems (more on that below).
21+
まだフックをサポートしてない `react-dom` (< 16.8.0) `react-native` (< 0.60) を利用しているのかもしれません。アプリケーションフォルダで `npm ls react-dom` `npm ls react-native` を実行して、どのバージョンを使っているのかを確認できます。もしも 2 つ以上出てきた場合は、それも問題になりえます(後述)。
2222

23-
## Breaking the Rules of Hooks {#breaking-the-rules-of-hooks}
23+
## フックのルールへの違反 {#breaking-the-rules-of-hooks}
2424

25-
You can only call Hooks **while React is rendering a function component**:
25+
フックを呼び出してよいのは **React が関数コンポーネントをレンダーしている最中**のみです。
2626

27-
*Call them at the top level in the body of a function component.
28-
*Call them at the top level in the body of a [custom Hook](/docs/hooks-custom.html).
27+
*関数コンポーネント本体のトップレベルで呼び出す。
28+
*[カスタムフック](/docs/hooks-custom.html)の本体のトップレベルで呼び出す。
2929

30-
**Learn more about this in the [Rules of Hooks](/docs/hooks-rules.html).**
30+
**詳しくは[フックのルール](/docs/hooks-rules.html)を参照してください。**
3131

3232
```js{2-3,8-9}
3333
function Counter() {
@@ -43,13 +43,13 @@ function useWindowWidth() {
4343
}
4444
```
4545

46-
To avoid confusion, it’s **not** supported to call Hooks in other cases:
46+
念のためですが、上記と異なる以下のようなケースでは、フックはサポート**されません**
4747

48-
* 🔴 Do not call Hooks in class components.
49-
* 🔴 Do not call in event handlers.
50-
* 🔴 Do not call Hooks inside functions passed to `useMemo`, `useReducer`, or `useEffect`.
48+
* 🔴 クラスコンポーネント内で呼び出さないでください。
49+
* 🔴 イベントハンドラ内で呼び出さないでください。
50+
* 🔴 `useMemo`, `useReducer`, `useEffect` に渡す関数の内部で呼び出さないでください。
5151

52-
If you break these rules, you might see this error.
52+
これらのルールに違反した場合には本エラーが発生します。
5353

5454
```js{3-4,11-12,20-21}
5555
function Bad1() {
@@ -78,26 +78,26 @@ class Bad3 extends React.Component {
7878
}
7979
```
8080

81-
You can use the [`eslint-plugin-react-hooks` plugin](https://www.npmjs.com/package/eslint-plugin-react-hooks) to catch some of these mistakes.
81+
これらの誤りの一部は [`eslint-plugin-react-hooks` プラグイン](https://www.npmjs.com/package/eslint-plugin-react-hooks)を利用すると検出できます。
8282

83-
>Note
83+
> 補足
8484
>
85-
>[Custom Hooks](/docs/hooks-custom.html) *may* call other Hooks (that's their whole purpose). This works because custom Hooks are also supposed to only be called while a function component is rendering.
85+
> [カスタムフック](/docs/hooks-custom.html)は他のフックを呼び出しても構いません(まさにそれが目的なので)。これはカスタムフックも関数コンポーネントがレンダーされる最中にのみ呼び出されるはずだからです。
8686
8787

88-
## Duplicate React {#duplicate-react}
88+
## 重複した React のコピー {#duplicate-react}
8989

90-
In order for Hooks to work, the `react` import from your application code needs to resolve to the same module as the `react` import from inside the `react-dom` package.
90+
フックが動作するためには、あなたのアプリケーションコード内で `react` インポート文を使った時に解決される `react` が、`react-dom` パッケージ内でインポートしている `react` と同じでなければなりません。
9191

92-
If these `react` imports resolve to two different exports objects, you will see this warning. This may happen if you **accidentally end up with two copies** of the `react` package.
92+
これらの `react` のインポート文が別々のオブジェクトへと解決された場合、この警告が発生します。これは**意図せず `react` パッケージの 2 つのコピーをプロジェクトに含めてしまった場合**に発生する可能性があります。
9393

94-
If you use Node for package management, you can run this check in your project folder:
94+
パッケージ管理に Node を使っている場合は、プロジェクトフォルダ内で以下を実行することで確認できます:
9595

9696
npm ls react
9797

98-
If you see more than one React, you'll need to figure out why this happens and fix your dependency tree. For example, maybe a library you're using incorrectly specifies `react` as a dependency (rather than a peer dependency). Until that library is fixed, [Yarn resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) is one possible workaround.
98+
もし React のコピーが 2 つ以上あった場合、その原因を突き止めて依存ツリーを修正する必要があります。例えばあなたの利用しているライブラリが `react` を peer dependency ではなく誤って dependency として使用しているのかもしれません。そのライブラリが修正されるまでは、[Yarn resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) が問題の回避策になりえます。
9999

100-
You can also try to debug this problem by adding some logs and restarting your development server:
100+
また、ログを加えて開発サーバを再起動することでもこの問題のデバッグが可能です。
101101

102102
```js
103103
// Add this in node_modules/react-dom/index.js
@@ -109,14 +109,14 @@ window.React2 = require('react');
109109
console.log(window.React1 === window.React2);
110110
```
111111

112-
If it prints `false` then you might have two Reacts and need to figure out why that happened. [This issue](https://github.com/facebook/react/issues/13991) includes some common reasons encountered by the community.
112+
これで `false` が出力された場合は React が 2 つ存在するということであり、原因を突き止める必要があるでしょう。[この issue](https://github.com/facebook/react/issues/13991) に、コミュニティ内で経験されたよくある原因がいくつか載っています。
113113

114-
This problem can also come up when you use `npm link` or an equivalent. In that case, your bundler might "see" two Reacts — one in application folder and one in your library folder. Assuming `myapp` and `mylib` are sibling folders, one possible fix is to run `npm link ../myapp/node_modules/react` from `mylib`. This should make the library use the application's React copy.
114+
この問題は `npm link` やその同等物を使った場合にも発生することがあります。このケースでは、あなたのアプリケーションフォルダにあるものとライブラリフォルダにあるものの、2 つの React がバンドラから "見えて" いるのかもしれません。ひとつの解決法は、`myapp` `mylib` が互いに兄弟関係にあるフォルダであるとして、`mylib` 側から `npm link ../myapp/node_modules/react` を実行する、というものです。これによりライブラリ側がアプリケーション側の React のコピーを使用するようになります。
115115

116-
>Note
116+
>補足
117117
>
118-
>In general, React supports using multiple independent copies on one page (for example, if an app and a third-party widget both use it). It only breaks if `require('react')` resolves differently between the component and the `react-dom` copy it was rendered with.
118+
>一般的には、ひとつのページ内で複数の独立した React のコピーを利用することはサポートされています(例えば、あなたのアプリケーションとサードパーティのウィジェットが別の React のコピーを利用する場合など)。問題が発生するのはコンポーネントとそれをレンダーしている `react-dom` との間で `require('react')` が違うものに解決された場合です。
119119
120-
## Other Causes {#other-causes}
120+
## その他の原因 {#other-causes}
121121

122-
If none of this worked, please comment in [this issue](https://github.com/facebook/react/issues/13991) and we'll try to help. Try to create a small reproducing example — you might discover the problem as you're doing it.
122+
以上のいずれもうまくいかなかった場合は、[この issue](https://github.com/facebook/react/issues/13991) にコメントしていただければできるだけお手伝いします。小さな再現コードの例を作るようにしてください -- そうする過程で自分で問題に気づけるかもしれません。

0 commit comments

Comments
 (0)