zoukankan      html  css  js  c++  java
  • React 创建元素的几种方式

    React 创建元素的几种方式

    星期五, 31. 三月 2017 09:15下午

    1. createClass

    创建React组件对应的类。render 接口是必须实现。

    var hello = React.createClass({
    	
    	render:function(){
    		return <div>  Hello ,world </div>
    	}	
    })
    

    2.createElement ,创建React组件实例。

    ReactElement.creatElement = function(type,config,children){
    
    }
    

    3.createFactory 通过工厂方法创建React组件实例。

    createFactory 调用了 creteElement 方法

    ReactElement.createFactory = function (type) {
    	var factory = ReactElement.createElement.bind(null, type);
    
    	 factory.type = type;
    	return factory;
    };
    

    4. cloneElement 克隆

    ReactElement.cloneElement = function (element, config, children) {
    	
    }
    

    5. es6 class 方式

    import  React,{ Component }  from 'react'
    
    class test extends Component {
    
    	render(){
    		retrun(
    			<div>  hello,world </div>
    		)
    	}
    	
    }
  • 相关阅读:
    周报说明8-4
    周报7-28
    日志-maven-c监控 周报7-21
    证明创建runnable实例和普通类时间一样长, 其实吧
    UE4开始之路
    js简单框架设计
    json中key为数字会自动排序问题
    u3动画
    工厂模式
    单例模式
  • 原文地址:https://www.cnblogs.com/kuachengshiyongbao/p/6653800.html
Copyright © 2011-2022 走看看