question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot import hooks directly from unpkg

See original GitHub issue

Hello,

hooks.module.js import from preact module, causing resolution failure when loading hooks as ES6 module. Should we import from preact.module.js in the same package instead?

This is how I load preact and preact/hooks:

import { h, render } from 'https://unpkg.com/preact@10.0.0-rc.3/dist/preact.module.js';
import { useState, useEffect } from 'https://unpkg.com/preact@10.0.0-rc.3/hooks/dist/hooks.module.js';

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
developitcommented, Oct 1, 2019

Hi there! You can use the following imports to load hooks from unpkg successfully:

import { h, render } from 'https://unpkg.com/preact@latest?module';
import { useState, useEffect } from 'https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module';

It’s important to note that subpackage versioning does not work on unpkg. This is something I’d like to fix but haven’t had the time to do.

Working example: https://codepen.io/developit/pen/XWrvXvo?editors=0010

8reactions
Kanayecommented, Oct 26, 2019

Hi @jgoux. Importing just the 3 modules from unpkg seems to work fine for me: example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use useState hook with Preact and no build tools?
Use already resolved URLs for each module (notice the @latest in the preact import). import { h, render } from 'https://unpkg.com/preact@latest?
Read more >
readme.md - UNPKG
For example, using a CDN: ```js import ky from ... Type: `Function[]`<br> Default: `[]` This hook enables you to modify the request right...
Read more >
react-hot-loader/README.md - UNPKG
Hooks would be auto updated on HMR if they _should_ be. 66, There is only one condition for it - a non zero...
Read more >
testing-library/react-hooks - UNPKG
1, import { ReactHooksRenderer } from './types/react'. 2. 3, const renderers = [. 4, { required: 'react-test-renderer', renderer: './native/pure' },.
Read more >
ng-lazyload-image/CHANGELOG.md - UNPKG
7, - In some cases users are facing the error: "useClass cannot be undefined". ... 15, import { LazyLoadImageModule, IntersectionObserverHooks, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found