gpt4 book ai didi

javascript - 故事书不渲染组件

转载 作者:行者123 更新时间:2023-12-05 02:00:33 24 4
gpt4 key购买 nike

这是我的组件:

Alert.tsx

import { Alert } from "react-bootstrap";

export enum AlertVariants {
success = "success",
danger = "danger",
}

export interface IAlertComponent {
handleClose(): void;
header: string;
children: string;
variant: AlertVariants;
}
export const AlertComponent = ({
handleClose,
header,
children,
variant,
}: IAlertComponent) => {
return (
<Alert variant={variant} onClose={handleClose} dismissible>
<Alert.Heading>{header}</Alert.Heading>
<p>{children}</p>
</Alert>
);
};

故事是这样的:

Alert.stories.tsx

import { Meta, Story } from "@storybook/react";
import {
AlertComponent,
IAlertComponent,
AlertVariants,
} from "../components/Alert";

const Template: Story<IAlertComponent> = (args) => <AlertComponent {...args} />;

export default {
title: "Alert",
component: AlertComponent,
} as Meta;

export const Alert = () => Template.bind({});
Alert.args = {
handleClose: () => console.log("close"),
header: "header",
children: "content",
variant: AlertVariants.danger,
};

export const tmp = () => <div>test</div>; // this gets rendered

在我运行 yarn storybook 之后,我看到了这个:

enter image description here

我做错了什么?

编辑:

如果我在 Alert.stories.tsx 中执行此操作,它会呈现。所以它必须是 smth 与 args

export const tmp = () => (
<AlertComponent
handleClose={() => {}}
header={"hedaer"}
variant={AlertVariants.danger}
>
test
</AlertComponent>
);

最佳答案

我一定是累了。我在做

export const Alert = () => Template.bind({});

代替

export const Alert = Template.bind({});

关于javascript - 故事书不渲染组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67246717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com