Skip to content

Added a new (very common) false Hook usage in Doc #3129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions content/warnings/invalid-hook-call-warning.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ There are three common reasons you might be seeing it:
1. You might have **mismatching versions** of React and React DOM.
2. You might be **breaking the [Rules of Hooks](/docs/hooks-rules.html)**.
3. You might have **more than one copy of React** in the same app.
4. You might be calling the component as `function` but not `component`.

Let's look at each of these cases.

Expand Down Expand Up @@ -117,6 +118,11 @@ This problem can also come up when you use `npm link` or an equivalent. In that
>
>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.

## Calling the component as `function` but not `component`
Calling a functional component as `function` (for example, calling `ComponentWithHook()` instead of `<ComponentWithHook />`) will **not** mount the component, and eliminate the whole react lifecycle. This will block Hook from working.

In this case, the solution is straightforward: just call `<ComponentWithHook />`, but not `ComponentWithHook()`.

## Other Causes {#other-causes}

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.