React 学习(二) 类组件的props

super

  • super(props): Superclass will help you to keep the props:[^props]

    import React, { Component } from "react";
    export default class App extends Component {
      constructor(props) {
        super(props);
      }
    
      render() {
        return (
          <div>App</div>
        );
      }
    }
    
  • But we use super() also can run

    import React, { Component } from "react";
    export default class App extends Component {
      constructor() {
        super();
      }
      render() {
        return (
          <div>App</div>
        );
      }
    }
    
  • Subclass will auto execute the constructor function, we can not write it

    import React, { Component } from "react";
    export default class App extends Component {
      render() {
        return (
          <div>App</div>
        );
      }
    }
    
posted @ 2020-11-26 17:38  北冥雪  阅读(186)  评论(0编辑  收藏  举报