React组件的生命周期各环节运做流程

'use strict';
React.createClass({
    //1.建立阶段
    getDefaultProps:function(){
        //在建立类的时候被调用
        console.log('getDefaultProps');
        return {};
    },
    //2.实例化阶段
    getInitialState:function(){
        //获取this.state的默认值
        console.log('getInitailState');
        return {};
    },
    componentWillMount:function(){
        //在render以前调用
        //业务逻辑的处理放这,如对state的操做
        console.log('componentWillMount');
    },
    render:function(){
        //渲染并返回一个虚拟DOM
        console.log('render');
        return (
            <h1>{this.props.value}</h1>
        );
    },
    componentDidMount:function(){
        //该方法发生在render方法以后。
        //在这里React会使用render方法返回的虚拟DOM对象来建立真实的DOM结构
        console.log('componentDidMount');
    },
    //3.更新阶段
    componentWillRecieveProps:function(){
        //该方法发生在this.props被修改或父组件调用setProps()方法以后
        console.log('componentWillRecieveProps');
    },
    shouldComponentUpdate:function(){
        //是否须要更新
        console.log('shouldComponentUpdate');
        return true;
    },
    componentWillUpdate:function(){
        //将要更新
        console.log('componentWillUpdate');
    },
    componentDidUpdate:function(){
        //更新完毕
        console.log('componentDidUpdate');
    },
    //4.销毁阶段
    componentWillUnmount:function(){
        //销毁时被调用
        console.log('componentWillUnmount');
    }
});
相关文章
相关标签/搜索