首页 > 其他 > 详细

React组件继承的由来

时间:2018-01-02 21:04:38      阅读:251      评论:0      收藏:0      [点我收藏+]

没有显式继承的时候我们这么写:

import * as React from "react";

export interface HelloProps { compiler: string; framework: string; }

export const Hello = (props: HelloProps) => <h1>Hello from {props.compiler} and {props.framework}!</h1>;

我们把它写的更像类一些:

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<HelloProps, {}> {
    render() {
        return <h1>Hello from {this.props.compiler} and {this.props.framework}!</h1>;
    }
}

  

React组件继承的由来

原文:https://www.cnblogs.com/yk123/p/8178699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!