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)