当我尝试导入组件“deleteButton”时,编译器声称该类不存在。
我尝试使用导出默认值,并在别名下导入它。
import React from 'react';
import deleteButton from './Components/deleteButton';
const App: React.FC = () => {
return (
<deleteButton/>
);
}
export default App;
import React from 'react';
import { confirmAlert } from 'react-confirm-alert';
import 'react-confirm-alert/src/react-confirm-alert.css';
export default class deleteButton extends React.Component {
submit = () => {
confirmAlert({
title: 'Confirm to delete',
message: 'Are you sure to delete this file?.',
buttons: [
{
label: 'Yes',
onClick: () => alert('File deleted')
},
{
label: 'No',
onClick: () => alert('Canceled')
}
]
});
};
render() {
return (<div className='container'>
<button onClick={this.submit}>Delete</button>
</div>);
}
}
预期的输出应该是一个 HTML 元素。编译器声称:“JSX.IntrinsicElements”类型上不存在属性“deleteButton”。TS2339