Cannot resolve name `React` when using preact v8.3.1 with Flow v0.79.1
See original GitHub issueI’m encountering the following issue when using flow
with preact
.
I’ve followed your flow integration doc but it’s not working as expected.
Error
[flow] Cannot resolve name `React`. (view.js:36:5)
(property) JSX.IntrinsicElements.h1: JSX.HTMLAttributes
Flow-IDE
h1: (unknown)
Code (Shortened)
/* @flow */
'use strict';
import { h, Component } from 'preact';
type Props = {};
type State = {};
export class HelloWorld extends Component<Props, State> {
constructor (props: Props) {
super(props);
this.state = { };
}
render (): any {
return (
<div class='hello-world'>
<h1>Hello World</h1> // This line fails
</div>
);
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Cannot resolve name `React` when using preact v8.3.1 with ...
I'm encountering the following issue when using flow with preact. I've followed your flow integration doc but it's not working as expected.
Read more >Switching to Preact (from React)
Switching to Preact can be as easy as installing and aliasing preact-compat in for react and react-dom . This lets you continue writing...
Read more >Flow: Throws error Cannot resolve module "react-redux" even ...
How to fix it. You have two options: stub the dependency by hand; bring in flow-typed to find the dependency type file/stub it...
Read more >preact-compat - npm
A React compatibility layer for Preact. Latest version: 3.19.0, last published: 3 years ago. Start using preact-compat in your project by ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding
/** @jsx h */
manually to the top of each file seems to do the trick. More typing but at least it’s working.Think adding something to the top of each file, not the best approach. There is a better way at least for TS
https://github.com/preactjs/preact#default
For using Preact along with TypeScript add to tsconfig.json:
{ “jsx”: “react”, “jsxFactory”: “h”, }