Skip to content

Unexpected "Hooks can only be called inside the body of a function component." #14317

Closed
@strayiker

Description

@strayiker

Do you want to request a feature or report a bug?
Report a bug.

What is the current behavior?
Using a custom hook from a locally linked package lead to the unexpected error "Hooks can only be called inside the body of a function component."

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
Here is the github repository to reproduce this error
Steps:

  • In the root folder run yarn
  • In the hook folder run yarn link
  • In the root run yarn link hook, then yarn start

You will see the error.

What is the expected behavior?
Code should work and do not throw an error.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React: 16.7.0-alpha.2
Browser: Chrome 70.0.3538.102
OS: Windows 7/10, Ubuntu 18.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions