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.

Preact X and hooks

See original GitHub issue

Hi.

I’ve installed the default template from the latest preact-cli. I’ve followed the migration guide and I’ve updated preact, preact-router and preact-render-to-string using the @next version.

I can run the preact-cli project without any problem. I can try the import { useState } from 'preact/hooks' and it works fine.

The problem is when I try to import a library I made for state management, that is using Hooks (via import { useState } from 'react'. Since Preact X already comes with preact-compat I don’t think its an alias issue but preact doesnt correctly map { useState } from 'react' to { useState } from 'preact/hooks'

I get the following error:

‼ WARN ./node_modules/snap-state/dist/snap-state.module.js
12:13-14 "export 'useState' (imported as 'n') was not found in 'react'
 @ ./node_modules/snap-state/dist/snap-state.module.js
 @ ./src/components/app.js
 @ ./src/index.js
 @ ./node_modules/preact-cli/lib/lib/entry.js
 @ multi ./node_modules/preact-cli/lib/lib/entry webpack-dev-server/client webpack/hot/dev-server
‼ WARN ./node_modules/snap-state/dist/snap-state.module.js
16:10-11 "export 'useEffect' (imported as 't') was not found in 'react'
 @ ./node_modules/snap-state/dist/snap-state.module.js
 @ ./src/components/app.js
 @ ./src/index.js
 @ ./node_modules/preact-cli/lib/lib/entry.js
 @ multi ./node_modules/preact-cli/lib/lib/entry webpack-dev-server/client webpack/hot/dev-server

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
marvinhagemeistercommented, Aug 6, 2019

@andrevenancio the default template installs an older version of preact-cli local to the project. You need to update that too (npm i -D preact-cli@rc).

1reaction
andrevenanciocommented, Aug 7, 2019

Oh I see. Alright, I’ll have a look at it, massive thanks for the help.

I’ll use this for now, and then hopefully when PreactX comes up preact-cli will also be out and about and all will look great.

Massive thanks for this, and maintaining the libraries. Both of you! ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks | Preact: Fast 3kb React alternative with the same ES6 ...
Hooks is a new concept that allows you to compose state and side effects. They allow you to reuse stateful logic between components....
Read more >
What's new in Preact X
New features and changes in Preact X. ... Fragments; componentDidCatch; Hooks; createContext; CSS Custom Properties; Compat lives in core ...
Read more >
Option Hooks | Preact: Fast 3kb React alternative with the ...
Preact supports a number of different callbacks that can be used to observe or change each stage of the rendering process, commonly referred...
Read more >
Upgrading from Preact 8.x
Preact X brings many new exciting features such as Fragments , hooks and much improved compatibility with the React ecosystem. We tried to...
Read more >
Components | Preact
Components represent the basic building block in Preact. They are fundamental in making it easy to ... This doesn't hold true anymore with...
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