[英]Export multiple components as one from the same file in react
有人可以帮我实现几个组件的导出
import { Card, Text } from "@nextui-org/react";
export default function App() {
const MockItem = ({ text }) => {
return (
<Card css={{ h: "$20", $$cardColor: '$colors$primary' }}>
<Card.Body>
<Text h6 size={15} color="white" css={{ m: 0 }}>
{text}
</Text>
</Card.Body>
</Card>
);
};
您可以从一个文件中导入所有模块,然后对其进行解构以获得您需要的内容。
import * as multipleComponents from "@nextui-org/react";
const { Card, Text } = multipleComponents;
只能有一个export default
,但可以有多个export const
例如
export default function ...
export const MyOtherComponent = () => ...
您可以将export const...
换成 export export function...
如果您愿意。
然后将它们导入另一个文件 -
import MyDefaultComponent, { MyOtherComponent } from '../path-to-components'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.