文章標題

import React, { Component } from ‘react’;
import {
AppRegistry,
StyleSheet,
Text,
View
} from ‘react-native’;

export default class xxs extends Component {
//1.創建階段
getDefaultProps() {
// 在創建類的時候被調用
console.log(“getDefaultProps–>getDefaultProps”);
}

// 構造
constructor(props) {
    super(props);
    //獲取this.state的默認值
    console.log("constructor-->constructor");
}



componentWillMount() {
    //在render之前調用此方法
    //在業務邏輯的處理都應該放在這裏,如對state的操作等
    console.log("componentWillMount-->"+"componentWillMount");

}





componentDidMount() {
    // 該方法發生在render方法之後,在該方法中,ReactJs會使用render方法返回的虛擬Dom對象來創建真實的Dom結構
    console.log("componentDidMount->componentDidMount");

}

//3.更新階段
componentWillRecieveProps() {
    //該方法發生在this.props被修改或父組件調用setProps()方法之後

    console.log("componentWillRecieveProps->componentWillRecieveProps");

}


shouldComponentUpdate() {
    //是否需要更新
    console.log("shouldComponentUpdate->shouldComponentUpdate");
    return true;
}


componentWillUpdate() {
    //將要更新
    console.log("componentWillUpdate->componentWillUpdate");

}


componentDidUpdate() {
    //更新完畢
    console.log("componentDidUpdate->componentDidUpdate");

}

//4.銷燬階段
componentWillUnmount() {
    //銷燬時被調用
    console.log("componentWillUnmount->componentWillUnmount");

}

render() {
    console.log('render');
    return (
        <View>
            <Text>
                Welcome to React Native!
            </Text>

        </View>
    );
}

}

AppRegistry.registerComponent(‘TestFinancing’, () => xxs);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章