简体   繁体   中英

Prettier / ESLint / React

Conflicting rules on TS / React import from a noob, but using Eslint / Prettier and getting an 'React' is declared but its value is never read. error, but if i remove it, 'React' must be in scope when using JSX error pops up. I can't work out why!

ReactDOM.render(<Hello greeting="Site under construction..." />, document.getElementById('root'));
import React from 'react';

export interface IProps {
    greeting: string;
}

function Hello({ greeting }: IProps) {
    return <div>{greeting}</div>;
}

export default Hello;

/Users/Jeremyrrsmith/Coding/GitHub/portfolio-site/src/components/Hello.tsx TypeScript error in /Users/Jeremyrrsmith/Coding/GitHub/portfolio-site/src/components/Hello.tsx(undefined,undefined):
'React' is declared but its value is never read. TS6133

But if I remove the import from Hello.tsx above

src/components/Hello.tsx
Line 6:12: 'React' must be in scope when using JSX react/react-in-jsx-scope

Search for the keywords to learn more about each error.

the last react version of react doesn t need the import. Use that one or fix your eslint which is the problem here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM