RN开发-ReactJS组件

虚拟DOM :将真实的DOM结构虚拟成json类型数据
    props : 不可改变,用于数据传递
    state : 组件属性,主要用来存储组件自身需要的数据,每次改变都会引起组件的更新
        (ReactJS内部监听state状态,state改变后会主动触发render方法更新虚拟DOM结构)
    
    1、生命周期
        (1). 创建         
            处理props的默认值,在React.createClass后调用
            getDefaultProps: function(){} 处理this.props默认值
        
        (2). 实例化         
            组件被调用的时候触发。
            getInitalState:function(){} 获取this.state默认值
            componentWillMount:function(){} 业务逻辑处理
            render:function(){} 渲染并返回一个DOM
            componentDidMount(){} render 中返回一个DOM结构,可以通过this.getDOMNode()获得DOM节点
        
        (3). 更新
            主要发生在用户操作或者父组件有更新后,会根据修改进行相应的页面结构调整
            componentWillReceiveProps:function(){} 在this.props被修改或者父组件调用setProps方法后
            shouldCompenetUpdate:function(){} 拦截props/state判断是否需要更新。返回true、false
            componentWillUpdate:function(){} 更新前操作
            render:function(){}
            componentDidUpdate:function(){} 更新
    
        (4). 销毁
            componentWillUnmount:fucntion(){}
            
    2、数据传递    
        (1). 子组件调用父组件
            在父组件中套用子组件,子组件的标签中添加属性name
            name={this.props.xxx}
        (2). 父组件调用子组件
            
            首先用属性ref='child'给子组件做标记
            this.refs.child.getDOMNode().xxx

原文地址:https://www.cnblogs.com/farmerkids/p/5972197.html