【发布时间】:2017-06-05 22:15:40
【问题描述】:
举个例子:
export interface IBaseIconProperties {
path: string;
}
export default class BaseIcon extends React.Component<IBaseIconProperties, any> {
public render() {
return (
<SvgIcon style={{width: 32, height: 32}}>
<path d={this.props.path} />
</SvgIcon>
);
}
}
export default class Foo extends React.Component<any, any> {
public render() {
return <BaseIcon path="/* SVG path for Foo button goes here... */"/>;
}
}
export default class Bar extends React.Component<any, any> {
public render() {
return <BaseIcon path="/* SVG path for Bar button goes here... */"/>;
}
}
这是使用 React 组件进行继承的一种方式。不确定是否可以调用此继承。
但是还有其他方法吗?更好的方法?也许通过BaseIcon 类是abstract 的实际继承?这是否可以在不使事情过于复杂的情况下以某种方式实现?
【问题讨论】:
标签: reactjs inheritance typescript components