【发布时间】:2019-11-03 20:48:20
【问题描述】:
我想扩展默认的 Material-UI 按钮以添加更多变体,例如“方形”。
如何定义prop接口来继承/组合props。
这是我的代码:
import React from "react";
import { Button as MuiButton } from "@material-ui/core";
import { ButtonProps as MuiButtonProps } from "@material-ui/core/Button";
interface ButtonProps extends MuiButtonProps {
variant?: "square";
}
const defaultProps = {};
const Button: React.FC<ButtonProps> = ({variant, children, ...props}) => {
return (
<MuiButton variant={variant} {...props}>
{props.children}
</MuiButton>;
)
};
Button.defaultProps = defaultProps;
export default Button;
理想情况下,我想像这样使用这个组件:
<ExtendedButton href="/" variant="square">Click Me!</ExtendedButton>
【问题讨论】:
标签: reactjs typescript material-ui