我想從React
組件繼承,並定義新的Props
。類似的東西(有很多的錯誤與Bar
,應該完全是錯誤的):flowtype:繼承和通用
// @flow
class Component<Props> {
props: Props;
constructor(props: Props) {
this.props = props;
}
}
type FooProps = {
x: number;
}
class Foo extends Component<FooProps> {
_render(value: string) {
return `hello, ${value}`;
}
render() {
return this._render(`${this.props.x}`);
}
};
type BarProps = {
x: number;
y: number;
}
class Bar extends Foo<BarProps> {
render() {
return this._render(`${this.props.x} ${this.props.y}`);
}
}
const foo: Foo = new Foo({x: 1});
const bar: Bar = new Bar({x: 1, y: 2});
我應該如何使用仿製藥流與繼承? (在React組件的上下文中,如果它很重要的話)。
使用流程0.57.2
並作出反應16.0.0
。
你是什麼意思繼承?在使用'React'的情況下,輸入組件時繼承不起作用。你只需要像'PropType'那樣輸入'props'' –
意思是'Bar'擴展'Foo','Bar'改變'props'的類型。我會再想一想... –