React Native生命周期

代碼如下:

'use strict';

import React, { Component } from 'react';

import {
  StyleSheet,
  View,
} from 'react-native';

class test extends Component {

    constructor(props) {
      super(props);

      this.state = {

      };
    }

    componentWillMount() {
        console.log('componentWillMount');

    }


    render() {
        console.log('render');
        return (
            <View />
            );
    }

    componentDidMount() {
        console.log('componentDidMount');      
    }

    componentWillUnmount() {
        console.log('componentWillUnmount');          
    }


    componentWillReceiveProps(nextProps) {
        console.log('componentWillReceiveProps');          
    }

    /*
    通常不用寫,添加shouldComponentUpdate方法一般都會拖慢組件的更新速度,
    詳見:《什麼時候要在React組件中寫shouldComponentUpdate?》
    http://www.infoq.com/cn/news/2016/07/react-shouldComponentUpdate

    shouldComponentUpdate(nextProps, nextState) {

    }
    */

    componentWillUpdate(nextProps, nextState) {
        console.log('componentWillUpdate');          
    }

    componentDidUpdate(prevProps, prevState) {
        console.log('componentDidUpdate');  
    }


}



const styles = StyleSheet.create({

});


module.exports = test;

results matching ""

    No results matching ""