zoukankan      html  css  js  c++  java
  • RN组件的生命周期

    来自:http://www.devio.org/tags/#React%20Native 

    最新版抛弃了一些方法

      constructor(props) {
        super(props);
    
        console.log('constructor')
        this.state=({
          title:'是'
        })
        this.textPress = this.textPress.bind(this);
      }
    
      //有了这个方法 带UNSAFE_前缀的都可以移除了
      static getDerivedStateFromProps(nextProps, prevState) {
        console.log(prevState)
        console.log('getDerivedStateFromProps')
        console.log(nextProps)
    
        // 否则,对于state不进行任何操作
        return null;
      }
    
      UNSAFE_componentWillMount(){
        console.log('UNSAFE_componentWillMount')
      }
    
      render() {
        console.log('render')
        return (
           <View style={{justifyContent: 'center',flex: 1,flexDirection: 'row',alignItems: 'center'}}>
           <TouchableOpacity onPress={()=>this.textPress()}>
              <Text>{this.state.title}</Text>
           </TouchableOpacity>
    
           </View>
        );
      }
    
      componentDidMount(){
        console.log('componentDidMount')
      }
    
      UNSAFE_componentWillReceiveProps(){
        console.log('UNSAFE_componentWillReceiveProps')
      }
    
      shouldComponentUpdate(){
        return true;
        console.log('shouldComponentUpdate')
      }
    
      UNSAFE_componentWillUpdate(){
        console.log('UNSAFE_componentWillUpdate')
      }
    
      //进入render...
    
      getSnapshotBeforeUpdate(){
        console.log('getSnapshotBeforeUpdate')
      }
    
      componentDidUpdate(){
        console.log('componentDidUpdate')
      }
    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    5. support vector machine
    机器学习实战(二)决策树
    机器学习实战(一)kNN
    深度学习笔记(无)VGG14
    深度学习笔记(一)线性分类器(基础知识)
    Eclipse代码风格
    windows安装java环境
    linux matlab2013b 安装教程
    小白Linux入门 五
    机器学习 0
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/11408573.html
Copyright © 2011-2022 走看看