[英]Is there a way to oraginize imports in vs code without removing 'react import'
I am trying to organize imports on saving a file.我正在尝试在保存文件时组织导入。 So I updated vs code settings to always organize imports when saving a file.
所以我更新了 VS 代码设置,以便在保存文件时始终组织导入。
But it also removes import React from 'react'
.但它也
import React from 'react'
。
So react gives me this error 'React' must be in scope when using JSX
.所以 React 给我这个错误
'React' must be in scope when using JSX
。
For eg,例如,
import React from 'react'
const Temp = () => {
return (
<div>Temp</div>
)
}
export default Temp
organizes to组织到
const Temp = () => {
return <div>Temp</div>;
};
export default Temp;
This is my react version - "react": "^16.13.1"
.这是我的 React 版本 -
"react": "^16.13.1"
。
Have you tried using a babel.config.js
file?您是否尝试过使用
babel.config.js
文件?
module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
['@babel/preset-react', { runtime: 'automatic' }],
],
};
I have a project that uses this and it works pretty fine.我有一个使用它的项目,它工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.