React component life cycle processes

Source: Internet
Author: User


‘Use strict’;
React.createClass ({
    // 1. Creation stage
    getDefaultProps: function () {
        // Called when creating a class
        console.log (‘getDefaultProps’);
        return {};
    },
    // 2. The instantiation phase
    getInitailState: function () {
        // Get the default value of this.state
        console.log (‘getInitailState’);
        return {};
    },
    componentWillMount: function () {
        // Call before render
        // The processing of business logic is put here, such as the operation of state
        console.log (‘componentWillMount’);
    },
    render: function () {
        // Render and return a virtual DOM
        console.log (‘render’);
        return (
            <h1> {this.props.value} </ h1>
        );
    },
    componentDidMount: function () {
        // This method occurs after the render method.
        // Here React will use the virtual DOM object returned by the render method to create a real DOM structure
        console.log (‘componentDidMount’);
    },
    // 3. Update stage
    componentWillRecieveProps: function () {
        // This method occurs after this.props is modified or the parent component calls setProps () method
        console.log (‘componentWillRecieveProps’);
    },
    shouldComponentUpdate: function () {
        // Do you need to update
        console.log (‘shouldComponentUpdate’);
        return true;
    },
    componentWillUpdate: function () {
        // will update
        console.log (‘componentWillUpdate’);
    },
    componentDidUpdate: function () {
        //update completed
        console.log (‘componentDidUpdate’);
    },
    // 4. Destruction phase
    componentWillUnmount: function () {
        // Called when destroyed
        console.log (‘componentWillUnmount’);
    }
}); 





React component life cycle processes


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.