Skip to content

Issue using Hooks with exported component #1757

@oliverdunk

Description

@oliverdunk

Bug

When I render an imported component which uses the useContext hook, I get the following error:

Uncaught TypeError: Cannot read property 'context' of undefined
    at Module.useContext (index.js:173)
    at d../src/example.tsx.exports.Example [as constructor] (example.tsx:7)

It appears that currentComponent is undefined, but I'm not sure what that means or how to fix it.

I think the issue is related to my build process, so have created a repository which demonstrates the problem.

Steps to reproduce

  1. Clone https://github.com/oliverdunk/preact-bug
  2. Run npm install
  3. Run npm run-script run

Expected behaviour

The number 5 is rendered on the page, inside of a H1.

Actual behaviour

When the Example component is rendered, the previously mentioned error is thrown.

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