React组件继承的由来
没有显式继承的时候我们这么写:
import * as React from "react";
export interface HelloProps { compiler: string; framework: string; }
export const Hello = (props: HelloProps) => Hello from {props.compiler} and {props.framework}!
;
我们把它写的更像类一些:
import * as React from "react";
export interface HelloProps { compiler: string; framework: string; }
// 'HelloProps' describes the shape of props.
// State is never set so we use the '{}' type.
export class Hello extends React.Component {
render() {
return Hello from {this.props.compiler} and {this.props.framework}!
;
}
}