这在tempselector.tsx文件中。
app.tsx文件具有以下代码:
import './App.css'
import tempSelector from "./tempSelector.tsx";
function App() {
return (
<>
<tempSelector />
</>
)
}
export default App
不幸的是,奇怪的是,我在app.tsx中看到以下汇编错误:
TS6133: 'tempSelector' is declared but its value is never read.
ESLint: 'tempSelector' is defined but never used. (@typescript-eslint/no-unused-vars)
TS2339: Property 'tempSelector' does not exist on type 'JSX.IntrinsicElements'.
没有人知道这里发生了什么?更重要的是:我该如何解决此问题?
不仅是导入的牙套,还不仅仅是导出的牙套。使用
ES6
,通常采用
default export
方法:
tempSelector.tsx
import {Autocomplete, TextField} from "@mui/material";
const theData = [
// ...data
];
const TempSelector = () => {
return(
{/* ...component */}
);
}
export default TempSelector;
export default function tempSelector() {/* ...content */}
.相同。
App.tsx
:
import TempSelector from "./tempSelector";
//...other codes
您也可以使用export
方法,但是语法将是:
tempSelector.tsx
:
import {Autocomplete, TextField} from "@mui/material";
const theData = [
// ...data
];
const TempSelector = () => {
return(
{/* ...component */}
);
}
export { TempSelector };
App.tsx
:
import { TempSelector } from "./tempSelector";
//...other codes