我有以下枚举
export enum Sizes{
Small,
Large
}
它正在我的 <Demo/>
中使用组件的 Prop 接口(interface):
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} />
关于reactjs - 如何在 react / typescript 中使用枚举作为 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49746638/