[英]React+Typescript, About namespace
I defined the class Header
in the header.tsx
file and put it in the BizComponent
namespace.我在
header.tsx
文件中定义了class Header
,放在BizComponent
命名空间中。
The footer.tsx
file defines the class Footer
and is also placed in this namespace. footer.tsx
文件定义了 class Footer
,也放在这个命名空间中。
How do I import this namespace so that it contains both classes?如何导入此名称空间以使其包含这两个类?
Thank you in advance for your answer.预先感谢您的回答。
UPDATE:更新:
header.tsx
: header.tsx
:
import React from 'react';
export namespace BizComponent {
export class Header extends React.Component {
render(): React.ReactNode {
return (<nav className='header-nav'>
<a className='left' href='/'>
<img className='header-logo' src='/logo.png' aria-label='logo' />
</a>
<div className='right'>
<a href='/article'>Article</a>
<a href='/about'>About</a>
</div>
</nav>);
}
}
}
export default BizComponent.Header;
footer.tsx
: footer.tsx
:
import React from 'react';
namespace BizComponent {
export class Footer extends React.Component {
render(): React.ReactNode {
return (<div>
<p className='footer'>
Copyright © 2022 (example). All rights reserved.
</p>
</div>);
}
}
}
export default BizComponent.Footer;
then import them...然后导入它们...
import { BizComponent } from './header.tsx';
// ERROR: TS 2300
// import { BizComponent } from './footer.tsx';
I'm looking for a way to replace this bad design...我正在寻找一种方法来取代这种糟糕的设计......
You have to import them separately using their relative file paths.您必须使用它们的相对文件路径分别导入它们。
One way to accomplish something similar is given in Importing a directory in React Importing a directory in React中给出了完成类似操作的一种方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.