英文:
A module cannot have multiple default exports in reactjs > typescript
问题
我有以下的项目树
src
Components
Create
Create.tsx
SuccessPage.tsx
index.ts
index.ts
index.ts
Create > index.ts
export { default } from "./Create";
export { default } from "./SuccessPage"; // 这里是错误
Component > index.ts
export { default as Create } from "./Create";
Src > index.ts
export * from './components';
我想要导出两个页面(create.tsx 和 success.tsx)
注意这两个页面包含两个类
class Create extends React.Component<IProps, IState> {
.....
}
export default Create;
和
class Success extends React.Component<IProps, IState> {
.....
}
export default Success;
我该如何做到这一点?
英文:
I have the following project tree
src
Components
Create
Create.tsx
SuccessPage.tsx
index.ts
index.ts
index.ts
Create > index.ts
export { default } from "./Create";
export { default } from "./SuccessPage"; // here is the error
Componenet > index.ts
export { default as Create } from "./Create";
Src > index.ts
export * from './components';
I want to export both pages ( create.tsx and success.tsx)
note that the pages contains 2 class
class Create extends React.Component<IProps, IState> {
.....
}
export default Create;
and
class Success extends React.Component<IProps, IState> {
.....
}
export default Success;
how can i do that?
答案1
得分: 0
将它们更改为具名导出,这样您可以拥有多个:
export { default as Create } from "./Create";
export { default as Success } from "./SuccessPage";
或者,您可以将其中一个保留为默认导出,但我怀疑这可能不是您真正想要的。
export { default } from "./Create";
export { default as Success } from "./SuccessPage";
英文:
Change them to named exports, so you can have multiple:
export { default as Create } from "./Create";
export { default as Success } from "./SuccessPage";
Alternatively, you could keep one of them as the default export, but I doubt that's really what you want.
export { default } from "./Create";
export { default as Success } from "./SuccessPage";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论