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
> 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.๏ผใใใฏใฏ้ขๆฐใณใณใใผใใณใใฎๆฌไฝใงใใๅผใณๅบใใพใใ๏ผ
10
10
11
-
There are three common reasons you might be seeing it:
## 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}
20
20
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 ใคไปฅไธๅบใฆใใๅ ดๅใฏใใใใๅ้กใซใชใใใพใ๏ผๅพ่ฟฐ๏ผใ
22
22
23
-
## Breaking the Rules of Hooks {#breaking-the-rules-of-hooks}
>[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.
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.
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.
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.
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.
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.
>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.
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.
0 commit comments