如何在反应/打字稿中使用枚举作为道具

空白脸

我有以下列举

export enum Sizes{
    Small,
    Large
}

在我的<Demo/>组件的props接口中正在使用

export interface IProps{
    Label?: string;
    Size: SizeEnum;
}

我的问题是,何时使用此功能<Demo Size={how do i define size here?} />

提香·切尔尼科娃·德拉戈米尔

您可以像在任何其他上下文中一样引用枚举值:

export enum Sizes{
    Small,
    Large
}

export interface IProps{
    Label?: string;
    Size: Sizes;
}

class Demo extends React.Component<IProps> {}

let d = <Demo Size={Sizes.Large} />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章