javascript - 故事书不渲染组件

标签 javascript reactjs typescript storybook

这是我的组件:

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/

相关文章:

javascript - 为什么包含()在javascript中不起作用

reactjs - React Router 将参数传递给组件

javascript - TypeScript 中的条件接口(interface)

javascript - 未捕获( promise )错误 : "Device" plugin is not implemented on android

javascript - 在javascript中查找并合并与数组的重复匹配

javascript - Jquery 到 React js

javascript - 给 child 编号

Angular 2 变化检测与 observables

visual-studio-2012 - Web Essential for Visual Studio 2012 中缺少 Typescript 选项

javascript - HTML5 命名空间元素的任何问题(IE 的无 js 解决方案)